unit-testingejbjunit5apache-tomeeopenejb

How to test EJB Beans in OpenEJB with JUnit5?


In JUnit 4, I use the following setup to test my EJB beans:

@RunWith(EJBContainerRunner.class)
public class MyEETestWithOneOpenEJB {
    @Inject
    private ACdiBean bean;
 
    @Test
    public void theTest() {
        // do test
    }
}

But in JUnit 5, there is no @RunWith(...) anymore.

Question: How to test with JUnit 5?


Solution

  • You will need to write your own EJBContainerExtension to replace the Runner or find an already existing one. The latter is unfortunately not very likely at this moment, JUnit5 is still not in GA and there are not many official extensions yet.

    If you want to, read about JUnit 5 extension model here