arquillian is nice, however, several projects don't need/use it.
several of them implemented a custom approach to control the cdi-container, start/stop scopes and check invalid state (esp. after a failed test). usually the basic tasks are the same or very similar. therefore i prototyped a deltaspike test-ctrl add-on based on some use-cases:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//starts the container once and one session + request per test-method | |
@RunWith(CdiTestRunner.class) | |
public class ContainerAndInjectionControl | |
{ | |
@Inject | |
private ApplicationScopedBean applicationScopedBean; | |
@Inject | |
private SessionScopedBean sessionScopedBean; | |
@Inject | |
private RequestScopedBean requestScopedBean; | |
//test the injected beans | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//starts the container and session once and one request per test-method | |
@RunWith(CdiTestRunner.class) | |
@TestControl(startScopes = SessionScoped.class) | |
public class CustomizedScopeHandling | |
{ | |
//inject beans and test them | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//starts the container once (for the whole suite) | |
@RunWith(CdiTestSuiteRunner.class) | |
@Suite.SuiteClasses({ | |
SimpleTest.class, | |
SimpleTestControlTest.class | |
}) | |
public class SuiteLevelContainerControl | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//fine-grained project-stage control | |
@RunWith(CdiTestRunner.class) | |
@TestControl(projectStage = CustomTestStage.class) //default: ProjectStage.UnitTest.class | |
public class TestStageControl | |
{ | |
//tests here will see project-stage CustomTestStage.class | |
@Test | |
@TestControl(projectStage = ProjectStage.Development.class) | |
public void checkDevEnv() | |
{ | |
} | |
//tests here will see project-stage CustomTestStage.class | |
} |
Update:
This add-on is part of all versions of DeltaSpike after v0.5