This framework has two modes:
AGAINST_SERVER - packaging tests in WAR with javaee-testing dependency and deployed alongside with application. If run tests from local machine framework find test on server, run it and return result.
OFFLINE - JavaEE container mocked by Spring. Tests run immediately without deployment.
Test mode chooses by test-mode property in javaee-testing.properties or by ping of deployed application (OFFLINE if fail).
- Create WAR artifact, add dependency for javaee-testing.
- Create test in main directory, add annotations:
@RequestScoped
@Stateful
@RunWith(JavaeeTestRunner.class)
- Create javaee-testing.properties file and add packageToScan property
- Add this WAR to application EAR and enjoy.
- Tests are standard JavaEE beans with injections, interceptions etc.
- New test instance creates for evert @Test (it's JUnit standard).
- Session lifecycle bounds to test class lifecycle. @Stateful beans will save state among test methods of one test class.
- @BeforeClass, @Before, @After, @AfterClass work as expected.
- CDI:
- @Inject, @EJB
- @Alternative, @Qualifier
- @Stateful with @SessionScope and @RequestScope
- @Interceptors (without changes of setParameters(), getContextData() and getTimer(), not controlled order of interceptors)
- Persistence:
- Supported: hsqldb
- @PersistenceContext injection
- @Transactional annotations
- bean transaction managements (without setting transaction timeout)
- MQ:
- Default provider - ActiveMQ
- Generate ConnectionFactories, Queues, Topics by fields in EJBs
- Create Listener by annotation (CF+destination)
Add javaee-testing.properties to you resources in WAR
- packageToScan - package for scan you JEE beans
- host - where to find deployed application default "localhost".
- port - default "8080".
- context-root - context root of WAR with tests default "javaee-testing".
- test-mode - AGAINST_SERVER or OFFLINE. Will choose by ping if not specified.
- Two different instances of same @Stateful bean in one object
- In JavaEE every module looks on own beans.xml. OFFLINE looks only on one in classpath.