JUnit5:在进行所有其他测试之前如何进行EJB初始化?

时间:2020-03-06 01:27:27

标签: ejb junit5

在JUnit4下,我有一个@ManagedBean类,我的所有集成测试都对其进行了扩展,并且预先使用@ClassRule在所有测试中为EJB样板仅执行了一次(请参见下文)。 @ClassRule消失了,我应该怎么做才能确保before()方法在所有其他测试之前运行?文档说要进行扩展,但是扩展应该是无状态的,这使我无法访问context之类的实例变量。

@ManagedBean
public class EJBStuff {

    public static Context context;

    @ClassRule
    public static final ExternalResource resource = new ExternalResource() {

         @Override
         protected void before() throws Exception {
            if (context == null) {
            final Properties p = new Properties();
            context = EJBContainer.createEJBContainer(p).getContext();
        }
    } 
}

如果我尝试对此代码进行扩展,扩展BeforeAllCallback并编写beforeAll方法,则会在EJBContainer.createEJBContainer()上收到此错误:

org.apache.openejb.OpenEjbContainer$InvalidApplicationException: 
org.apache.openejb.config.ValidationFailedException: Module failed validation. AppModule(name=)

我要用JUnit 5做些什么吗?

0 个答案:

没有答案
相关问题