Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 如何使用JUnit5在OpenEJB中测试EJB bean?_Unit Testing_Ejb_Junit5_Apache Tomee_Openejb - Fatal编程技术网

Unit testing 如何使用JUnit5在OpenEJB中测试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

在JUnit 4中,我使用以下设置来测试EJB bean:

@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>