You might give DeltaSpike CdiTestRunner a try. It cleans the contexts between test methods.
Just use cdictrl-openejb as backend. LieGrue, Strub > Am 30.09.2016 um 11:45 schrieb Xavier Dury <[email protected]>: > > Hi, > > Is it normal that all test methods from a test class running with > EJBContainerRunner share one single request context? > If the request context is shared between methods, this can cause some > unwanted dependency between them. > > Example: > > public @ApplicationScoped class ScopeService { > public void print(String message) { System.out.println(message); } > public void onInitialized(@Observes @Initialized(RequestScoped.class) > Object event) { System.out.println("initialized request context"); } > public void onDestroyed(@Observes @Destroyed(RequestScoped.class) Object > event) { System.out.println("destroyed request context"); } > } > > public @RunWith(EJBContainerRunner.class) class ContainerScopeTest { > public @Inject ScopeService service; > public @Test void test1() { this.service.print("test1"); } > public @Test void test2() { this.service.print("test2"); } > } > > gives the following logs: > > ... > INFO - Deployed Application(path=D:\development\workspaces\sdpsp\arquillian) > initialized request context > test2 > test1 > INFO - Undeploying app: D:\development\workspaces\sdpsp\arquillian > destroyed request context > INFO - Destroying OpenEJB container > > A test with arquillian like this one: > > public @RunWith(Arquillian.class) class ArquillianScopeTest { > public @Deployment static JavaArchive deploy() { return > ShrinkWrap.create(JavaArchive.class).addClasses(ScopeService.class).addAsManifestResource(EmptyAsset.INSTANCE, > "beans.xml"); } > public @Inject ScopeService service; > public @Test void test1() { this.service.print("test1"); } > public @Test void test2() { this.service.print("test2"); } > } > > gives the following logs: > > ... > INFO - Deployed > Application(path=D:\development\workspaces\sdpsp\arquillian\9ee795c0-40e2-47b9-b384-c923f525aefd.jar) > initialized request context > test1 > destroyed request context > initialized request context > destroyed request context > initialized request context > test2 > destroyed request context > initialized request context > destroyed request context > INFO - Undeploying app: > D:\development\workspaces\sdpsp\arquillian\9ee795c0-40e2-47b9-b384-c923f525aefd.jar > INFO - Destroying container system > > There are too many request context initialized/destroyed with arquillian but > at least each test gets its own context. > > With ApplicationComposer, a new container is started/stopped for each each > test so they each run with their own request context. > > Xavier
