我們在maven中創建了一個用於運行我們的Selenium junit4類型測試的配置文件,下面是沒有執行代碼的代碼片段。運行JUnit 4測試與FailSafe和SureFire插件並行
<profile>
<id>selenium-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.11</version>
<dependencies>
<!-- Force using the latest JUnit 47 provider -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.11</version>
</dependency>
</dependencies>
<configuration>
<parallel>classes</parallel>
<threadCount>5</threadCount>
<forkMode>pertest</forkMode>
<useManifestOnlyJar>false</useManifestOnlyJar>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<skip>false</skip>
<includes>
<include>**/regtests/*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
而我的TestClass看起來像這樣。
@RunWith(HTMLSourceDumperJUnit4Runner.class) //Our own Runner
public class MyTestClass extends Assert {
private int x = 1;
private int y = 1;
@Test
public void testAddition() {
int z = x + y;
assertEquals(2, z);
}
}
當我通過具有並行配置的故障安全插件2.11運行此測試類時,它會失敗並顯示以下錯誤。
java.lang.Exception: No runnable methods at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:171) at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:115) at org.junit.runners.ParentRunner.validate(ParentRunner.java:269) at org.junit.runners.ParentRunner.(ParentRunner.java:66) at org.junit.runners.BlockJUnit4ClassRunner.(BlockJUnit4ClassRunner.java:59) at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29) at org.junit.runner.Computer.getRunner(Computer.java:38) at org.apache.maven.surefire.junitcore.ConfigurableParallelComputer.getRunner(ConfigurableParallelComputer.java:142) at org.junit.runner.Computer$1.runnerForClass(Computer.java:29) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57) at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:93) at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:84) at org.junit.runners.Suite.(Suite.java:79) at org.junit.runner.Computer.getSuite(Computer.java:26) at org.apache.maven.surefire.junitcore.ConfigurableParallelComputer.getSuite(ConfigurableParallelComputer.java:134) at org.junit.runner.Request.classes(Request.java:69) at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:53) at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:188) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:166) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:86) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:101) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
有什麼我在這裏失蹤。如果我對這篇文章的任何信息滯後,請回復。
你也是混合版本; surefire-junit47依賴關係應該遵循故障安全版本; 2.11而不是2.8 – krosenvold 2012-01-13 08:58:41
謝謝..我試過這個,仍然顯示相同的錯誤。我已經用最新的嘗試更新了問題。 – raksja 2012-01-14 03:25:58
只需從2.10升級到surefire 2.11,就可以打破每個單元測試的錯誤,包括上面的錯誤 - 無論是否嘗試新的並行東西。所有的測試都是有效的JUnit 4類型測試,可以在2.10和之前的版本中正常工作。我花了幾個小時試圖弄清楚,有時間等到2.12。我所做的類似的是forkMode,useManifestOnlyJar和redirectOutputToFile設置。也許嘗試不同的設置爲一些或所有這些? – 2012-01-17 04:12:24