java - Pax Exam j2ee 集成测试,如何使用自定义 war probe 编写多个测试类?

标签 java wildfly pax-exam

我使用 wildfly 8.2.0.Final 作为 Pax Exam 4.5.0 java ee 集成测试的 Java EE 容器。

如果我只使用一个测试类,那么它工作正常。但是,如果我使用了多个测试类,则会显示以下错误:

using the PerSuite reactor strategy, all test classes must share the same probes

我该如何解决这个问题?

重现步骤:

 1. git clone https://github.com/saycchai/paxExamTest.git
 2. modify pom.properties and exam.properties for the wildfly path
 3. cd paxExamTest
 4. mvn clean test


异常如下

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building CounterWebApp 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ CounterWebApp ---
[INFO] Deleting d:\temp\paxExamTest\target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ CounterWebApp ---
[WARNING] Using platform encoding (MS950_HKSCS actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory d:\temp\paxExamTest\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ CounterWebApp ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ CounterWebApp ---
[WARNING] Using platform encoding (MS950_HKSCS actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 4 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ CounterWebApp ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding MS950_HKSCS, i.e. build is platform dependent!
[INFO] Compiling 4 source files to d:\temp\paxExamTest\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ CounterWebApp ---
[INFO] Surefire report directory: d:\temp\paxExamTest\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.cchai.test.BaseTest
15:35:24.220 [main] INFO  o.o.pax.exam.spi.DefaultExamSystem - Pax Exam System (Version: 4.5.0) created.
15:35:24.250 [main] INFO  o.o.pax.exam.junit.impl.ProbeRunner - creating PaxExam runner for class com.cchai.test.BaseTest
15:35:24.369 [main] INFO  o.o.pax.exam.junit.impl.ProbeRunner - running test class com.cchai.test.BaseTest
15:35:24.370 [main] INFO  o.o.p.e.w.WildFly80TestContainer - using existing WildFly installation in D:/java/JBoss/wildfly-8.2.0.Final
15:35:24.370 [main] INFO  o.o.p.e.w.WildFly80TestContainer - copying src\test\resources\wildfly80-config\standalone.xml to D:\java\JBoss\wildfly-8.2.0.Final\standalone\configuration\standalone.xml
15:35:24.770 [main] INFO  org.jboss.msc - JBoss MSC version 1.2.2.Final
15:35:24.879 [MSC service thread 1-6] INFO  org.jboss.as - JBAS015899: WildFly 8.2.0.Final "Tweek" starting
15:35:25.917 [Controller Boot Thread] INFO  org.jboss.as.server - JBAS015888: Creating http management service using socket-binding (management-http)
15:35:25.937 [MSC service thread 1-5] INFO  org.xnio - XNIO version 3.3.0.Final
15:35:25.944 [MSC service thread 1-5] INFO  org.xnio.nio - XNIO NIO Implementation Version 3.3.0.Final
15:35:25.991 [ServerService Thread Pool -- 32] INFO  org.jboss.as.clustering.infinispan - JBAS010280: Activating Infinispan subsystem.
15:35:25.995 [ServerService Thread Pool -- 45] INFO  org.jboss.as.security - JBAS013171: Activating Security Subsystem
15:35:25.995 [ServerService Thread Pool -- 46] WARN  org.jboss.as.txn - JBAS010153: Node identifier property is set to the default value. Please make sure it is unique.
15:35:25.995 [ServerService Thread Pool -- 40] INFO  org.jboss.as.naming - JBAS011800: Activating Naming Subsystem
15:35:26.000 [ServerService Thread Pool -- 31] INFO  org.wildfly.extension.io - WFLYIO001: Worker 'default' has auto-configured to 16 core threads with 128 task threads based on your 8 available processors
15:35:26.003 [ServerService Thread Pool -- 48] INFO  org.jboss.as.webservices - JBAS015537: Activating WebServices Extension
15:35:26.010 [MSC service thread 1-15] INFO  org.jboss.as.security - JBAS013170: Current PicketBox version=4.0.21.Final
15:35:26.026 [ServerService Thread Pool -- 38] INFO  org.jboss.as.jsf - JBAS012615: Activated the following JSF Implementations: [main]
15:35:26.027 [MSC service thread 1-14] INFO  org.jboss.as.connector.logging - JBAS010408: Starting JCA Subsystem (IronJacamar 1.1.9.Final)
15:35:26.037 [ServerService Thread Pool -- 47] INFO  org.wildfly.extension.undertow - JBAS017502: Undertow 1.1.0.Final starting
15:35:26.038 [MSC service thread 1-1] INFO  org.wildfly.extension.undertow - JBAS017502: Undertow 1.1.0.Final starting
15:35:26.206 [ServerService Thread Pool -- 27] INFO  o.j.a.c.subsystems.datasources - JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
15:35:26.217 [MSC service thread 1-12] INFO  org.jboss.as.naming - JBAS011802: Starting Naming Service
15:35:26.219 [MSC service thread 1-12] INFO  org.jboss.as.mail.extension - JBAS015400: Bound mail session [java:jboss/mail/Default]
15:35:26.224 [MSC service thread 1-9] INFO  o.jboss.as.connector.deployers.jdbc - JBAS010417: Started Driver service with driver-name = h2
15:35:26.267 [ServerService Thread Pool -- 47] INFO  org.wildfly.extension.undertow - JBAS017527: Creating file handler for path D:\java\JBoss\wildfly-8.2.0.Final/welcome-content
15:35:26.374 [MSC service thread 1-2] INFO  org.wildfly.extension.undertow - JBAS017525: Started server default-server.
15:35:26.380 [MSC service thread 1-5] INFO  org.jboss.remoting - JBoss Remoting version 4.0.6.Final
15:35:26.382 [MSC service thread 1-15] INFO  com.arjuna.ats.jbossatx - ARJUNA032010: JBossTS Recovery Service (tag: 9aa71) - JBoss Inc.
15:35:26.387 [MSC service thread 1-2] INFO  org.wildfly.extension.undertow - JBAS017531: Host default-host starting
15:35:26.400 [MSC service thread 1-15] INFO  com.arjuna.ats.arjuna - ARJUNA012324: Start RecoveryActivators
15:35:26.412 [Transaction Expired Entry Monitor] INFO  com.arjuna.ats.arjuna - ARJUNA012296: ExpiredEntryMonitor running at 三, 13 5月 2015 15:35:26
15:35:26.438 [MSC service thread 1-15] INFO  com.arjuna.ats.arjuna - ARJUNA012343: RecoveryManagerImple is ready. Socket listener is turned off.
15:35:26.438 [MSC service thread 1-15] INFO  com.arjuna.ats.jbossatx - ARJUNA032013: Starting transaction recovery manager
15:35:26.464 [MSC service thread 1-11] INFO  org.wildfly.extension.undertow - JBAS017519: Undertow HTTP listener default listening on /127.0.0.1:8080
15:35:26.489 [MSC service thread 1-15] INFO  com.arjuna.ats.jbossatx - ARJUNA032017: JBossTS Transaction Service (JTA version - tag: 9aa71) - JBoss Inc.
15:35:26.555 [MSC service thread 1-14] INFO  o.jboss.as.server.deployment.scanner - JBAS015012: Started FileSystemDeploymentService for directory D:\java\JBoss\wildfly-8.2.0.Final\standalone\deployments
15:35:26.568 [MSC service thread 1-7] INFO  o.j.a.c.subsystems.datasources - JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
15:35:26.741 [MSC service thread 1-11] INFO  org.jboss.ws.common.management - JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.3.2.Final
15:35:26.865 [Controller Boot Thread] INFO  org.jboss.as - JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
15:35:26.865 [Controller Boot Thread] INFO  org.jboss.as - JBAS015951: Admin console listening on http://127.0.0.1:9990
15:35:26.866 [Controller Boot Thread] INFO  org.jboss.as - JBAS015874: WildFly 8.2.0.Final "Tweek" started in 2323ms - Started 184 of 234 services (82 services are lazy, passive or on-demand)
15:35:27.484 [main] INFO  o.ops4j.pax.exam.spi.war.WarBuilder - WAR probe = file:/d:/windows/TEMP/1431502524224-0/test.war
15:35:27.507 [main] INFO  org.xnio - XNIO version 3.3.0.Final
15:35:27.517 [main] INFO  org.xnio.nio - XNIO NIO Implementation Version 3.3.0.Final
15:35:27.544 [main] INFO  org.jboss.remoting - JBoss Remoting version 4.0.6.Final
15:35:28.322 [management-handler-thread - 1] INFO  org.jboss.as.repository - JBAS014900: Content added at location d:\windows\TEMP\1431502524224-0\data\content\b9\e9af7104090f2afdf0ddb33fcb4b2a44fd32b5\content
15:35:28.333 [MSC service thread 1-4] INFO  org.jboss.as.server.deployment - JBAS015876: Starting deployment of "Pax-Exam-Probe.war" (runtime-name: "Pax-Exam-Probe.war")
15:35:29.527 [MSC service thread 1-11] INFO  org.jboss.weld.deployer - JBAS016002: Processing weld deployment Pax-Exam-Probe.war
15:35:29.590 [MSC service thread 1-11] INFO  o.h.validator.internal.util.Version - HV000001: Hibernate Validator 5.1.3.Final
15:35:29.799 [MSC service thread 1-10] INFO  org.jboss.weld.deployer - JBAS016005: Starting Services for CDI deployment: Pax-Exam-Probe.war
15:35:29.830 [MSC service thread 1-10] INFO  org.jboss.weld.Version - WELD-000900: 2.2.6 (Final)
15:35:29.869 [MSC service thread 1-7] INFO  org.jboss.weld.deployer - JBAS016008: Starting weld service for deployment Pax-Exam-Probe.war
15:35:30.774 [MSC service thread 1-2] INFO  org.wildfly.extension.undertow - JBAS017534: Registered web context: /Pax-Exam-Probe
15:35:30.914 [management-handler-thread - 1] INFO  org.jboss.as.server - JBAS018559: Deployed "Pax-Exam-Probe.war" (runtime-name : "Pax-Exam-Probe.war")
15:35:31.171 [default task-1] INFO  o.o.p.exam.servlet.TestRunnerServlet - TestRunnerServlet loaded
15:35:31.237 [main] INFO  o.o.p.e.spi.reactors.ReactorManager - suite finished
15:35:31.272 [MSC service thread 1-1] INFO  org.wildfly.extension.undertow - JBAS017535: Unregistered web context: /Pax-Exam-Probe
15:35:31.293 [MSC service thread 1-16] INFO  org.wildfly.extension.undertow - JBAS017532: Host default-host stopping
15:35:31.297 [MSC service thread 1-14] INFO  o.j.a.c.subsystems.datasources - JBAS010409: Unbound data source [java:jboss/datasources/ExampleDS]
15:35:31.297 [MSC service thread 1-14] INFO  org.jboss.weld.deployer - JBAS016009: Stopping weld service for deployment Pax-Exam-Probe.war
15:35:31.301 [MSC service thread 1-6] INFO  o.jboss.as.connector.deployers.jdbc - JBAS010418: Stopped Driver service with driver-name = h2
15:35:31.310 [MSC service thread 1-12] INFO  com.arjuna.ats.jbossatx - ARJUNA032018: Destroying TransactionManagerService
15:35:31.311 [MSC service thread 1-4] INFO  com.arjuna.ats.jbossatx - ARJUNA032014: Stopping transaction recovery manager
15:35:31.313 [MSC service thread 1-16] INFO  org.wildfly.extension.undertow - JBAS017521: Undertow HTTP listener default suspending
15:35:31.315 [MSC service thread 1-16] INFO  org.wildfly.extension.undertow - JBAS017520: Undertow HTTP listener default stopped, was bound to /127.0.0.1:8080
15:35:31.318 [MSC service thread 1-11] INFO  org.wildfly.extension.undertow - JBAS017506: Undertow 1.1.0.Final stopping
15:35:31.394 [MSC service thread 1-14] INFO  org.jboss.as.server.deployment - JBAS015877: Stopped deployment Pax-Exam-Probe.war (runtime-name: Pax-Exam-Probe.war) in 144ms
15:35:31.397 [MSC service thread 1-9] INFO  org.jboss.as - JBAS015950: WildFly 8.2.0.Final "Tweek" stopped in 146ms
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.407 sec
Running com.cchai.test.ejb.FirstTest
15:35:31.405 [main] INFO  o.o.pax.exam.junit.impl.ProbeRunner - creating PaxExam runner for class com.cchai.test.ejb.FirstTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.001 sec <<< FAILURE!
initializationError(com.cchai.test.ejb.FirstTest)  Time elapsed: 0.001 sec  <<< ERROR!
org.ops4j.pax.exam.TestContainerException: using the PerSuite reactor strategy, all test classes must share the same probes
    at org.ops4j.pax.exam.spi.reactors.SingletonStagedReactor.getInstance(SingletonStagedReactor.java:99)
    at org.ops4j.pax.exam.spi.reactors.PerSuiteStagedReactor.<init>(PerSuiteStagedReactor.java:43)
    at org.ops4j.pax.exam.spi.reactors.PerSuite.create(PerSuite.java:36)
    at org.ops4j.pax.exam.spi.DefaultExamReactor.stage(DefaultExamReactor.java:89)
    at org.ops4j.pax.exam.spi.reactors.ReactorManager.stageReactor(ReactorManager.java:198)
    at org.ops4j.pax.exam.junit.impl.ProbeRunner.<init>(ProbeRunner.java:80)
    at org.ops4j.pax.exam.junit.PaxExam.createDelegate(PaxExam.java:82)
    at org.ops4j.pax.exam.junit.PaxExam.<init>(PaxExam.java:73)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:250)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

Running com.cchai.test.ejb.SecondTest
15:35:31.410 [main] INFO  o.o.pax.exam.junit.impl.ProbeRunner - creating PaxExam runner for class com.cchai.test.ejb.SecondTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.001 sec <<< FAILURE!
initializationError(com.cchai.test.ejb.SecondTest)  Time elapsed: 0 sec  <<< ERROR!
org.ops4j.pax.exam.TestContainerException: using the PerSuite reactor strategy, all test classes must share the same probes
    at org.ops4j.pax.exam.spi.reactors.SingletonStagedReactor.getInstance(SingletonStagedReactor.java:99)
    at org.ops4j.pax.exam.spi.reactors.PerSuiteStagedReactor.<init>(PerSuiteStagedReactor.java:43)
    at org.ops4j.pax.exam.spi.reactors.PerSuite.create(PerSuite.java:36)
    at org.ops4j.pax.exam.spi.DefaultExamReactor.stage(DefaultExamReactor.java:89)
    at org.ops4j.pax.exam.spi.reactors.ReactorManager.stageReactor(ReactorManager.java:198)
    at org.ops4j.pax.exam.junit.impl.ProbeRunner.<init>(ProbeRunner.java:80)
    at org.ops4j.pax.exam.junit.PaxExam.createDelegate(PaxExam.java:82)
    at org.ops4j.pax.exam.junit.PaxExam.<init>(PaxExam.java:73)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:250)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)


Results :

Tests in error: 
  initializationError(com.cchai.test.ejb.FirstTest): using the PerSuite reactor strategy, all test classes must share the same probes
  initializationError(com.cchai.test.ejb.SecondTest): using the PerSuite reactor strategy, all test classes must share the same probes

Tests run: 3, Failures: 0, Errors: 2, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.809 s
[INFO] Finished at: 2015-05-13T15:35:31+08:00
[INFO] Final Memory: 27M/270M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project CounterWebApp: There are test failures.
[ERROR] 
[ERROR] Please refer to d:\temp\paxExamTest\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

最佳答案

您可以创建一个实现 org.ops4j.pax.exam.ConfigurationFactory 的类并通过 META-INF/services 注册它。然后,该工厂将提供用于您套件中所有类的配置。

关于java - Pax Exam j2ee 集成测试,如何使用自定义 war probe 编写多个测试类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30208609/

相关文章:

mysql - 无法创建请求的服务[org.hibernate.engine.jdbc.env.spi.JdbcEnvironment](尝试使用EntityManager)

java - 在 Pax Exam 包含的测试中访问编译资源

java - 线程 "Thread 2"在 JavaFX 应用程序中做什么?

java - 使用@MockBean 或@Autowired 在测试中模拟

java - 为什么我无法使用 WildFly 中的 WEB-INF/classes 中的 getResourceAsStream 读取属性文件?

java - Wildfly 16.0.0.Final 和 ejb-client 与安全领域的连接

java - Mysql流式结果集和jOOQ fetchLazy

java - BusinessObject 的 IEnterpriseSession 可以像数据库连接一样被缓存吗?

java - Pax Exam/Karaf - 在测试设置上安装功能

maven - Pax Exam 4 和多个 Maven 存储库无法正常工作