Unit testing 如何使用JUnit5在OpenEJB中测试EJB bean?
在JUnit 4中,我使用以下设置来测试EJB bean:Unit testing 如何使用JUnit5在OpenEJB中测试EJB bean?,unit-testing,ejb,junit5,apache-tomee,openejb,Unit Testing,Ejb,Junit5,Apache Tomee,Openejb,在JUnit 4中,我使用以下设置来测试EJB bean: @RunWith(EJBContainerRunner.class) public class MyEETestWithOneOpenEJB { @Inject private ACdiBean bean; @Test public void theTest() { // do test } } 但是在JUnit5中,不再有@RunWith(…) 问题:如何使用JUnit 5
@RunWith(EJBContainerRunner.class)
public class MyEETestWithOneOpenEJB {
@Inject
private ACdiBean bean;
@Test
public void theTest() {
// do test
}
}
但是在JUnit5中,不再有@RunWith(…)
问题:如何使用JUnit 5进行测试?您需要编写自己的EJBContainerExtension来替换运行程序或查找现有的运行程序。不幸的是,后者目前不太可能出现,JUnit5仍然不在GA中,并且还没有很多正式的扩展
即将发布的TomEE 8(目前为8.0.7-SNAPSHOT)将只支持使用JUnit 5进行测试(没有对JUnit 4的暂时依赖) 传统方式 传统的
EJBContainerRunner
被相关的JUnit 5扩展取代
如果您使用的是Maven,则需要将以下依赖项添加到pom
文件中:
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>openejb-junit5-backward</artifactId>
<version>8.0.7-SNAPSHOT</version>
<scope>test</scope>
</dependency>
与
这是一个纯JUnit5扩展。不需要在类路径中添加任何JUnit4依赖项。可以在TomEE GitHub存储库的中找到使用示例
现代方式
在同一版本中,ApplicationComposer
得到了增强,以支持JUnit5作为扩展。要使用它,请添加
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>openejb-junit5-backward</artifactId>
<version>8.0.7-SNAPSHOT</version>
<scope>test</scope>
</dependency>
org.apache.tomee
@RunWithEjbContainer
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>openejb-junit5-backward</artifactId>
<version>8.0.7-SNAPSHOT</version>
<scope>test</scope>
</dependency>