这通常是由于在测试类中创建了多个实例而导致的。可以通过将@Deployment注释到单独的方法中来解决此问题,而不是在测试类中使用构造函数或@PostConstruct之类的方法创建多个实例。例如:
@RunWith(Arquillian.class)
public class MyTest {
@Deployment
public static Archive> createDeployment() {
// create and return deployment archive
}
@Test
public void myTest() {
// test method code here
}
}
如果仍然遇到问题,可以尝试使用@RunAsClient注释在客户端模式下运行测试以避免重复的EJBContext错误。例如:
@RunWith(Arquillian.class)
public class MyTest {
@Deployment
public static Archive> createDeployment() {
// create and return deployment archive
}
@Test
@RunAsClient
public void myTest() {
// test method code here
}
}
如果仍然无法解决问题,则可能需要进一步检查测试类的代码以查找其他可能导致重复EJBContext错误的因素。
下一篇:Arquillian测试未失败