在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做些什么吗?