2013-04-30 146 views
3

我有steup Eclipse + Maven + TestNG,我打算運行Selenium測試用例。Maven在運行testng測試用例時拋出錯誤

這是我的POM文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>MyGroupId</groupId> 
<artifactId>TestSuite</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<dependencies> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>2.32.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.maven.surefire</groupId> 
     <artifactId>surefire-testng</artifactId> 
     <version>2.14.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.testng</groupId> 
     <artifactId>testng</artifactId> 
     <version>6.8.1</version> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 
</project> 

現在,當我嘗試運行Maven的測試,我得到以下錯誤:

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
org.apache.maven.surefire.util.SurefireReflectionException: 
java.lang.reflect.InvocationTargetException; nested exception is 
java.lang.reflect.InvocationTargetException: null 
java.lang.reflect.InvocationTargetException 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at 
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:525) 
at org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:130) 
at org.apache.maven.surefire.booter.SurefireReflector.instantiateProvider(SurefireReflector.java:247) 
at org.apache.maven.surefire.booter.ProviderFactory.createProvider(ProviderFactory.java:81) 
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:171) 
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107) 
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68) 
Caused by: java.lang.NoSuchMethodError: org.apache.maven.surefire.providerapi.ProviderParameters.getRunOrderCalculator()Lorg/apache/maven/surefire/util/RunOrderCalculator; 
at org.apache.maven.surefire.testng.TestNGProvider.<init>(TestNGProvider.java:67) 
... 10 more 

Results : 

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

有人建議我有什麼,我很想念這裏。

在此先感謝。

回答

6

您有類似下面的pluginManagement部分定義maven-surefire-plugin

<build> 
    <pluginManagement> 
     <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.14.1</version> 
     </plugin> 
     </plugins> 
    </pluginManagement> 
    </build> 

要與Maven的萬無一失,插件,你通常只需要添加TestNG的作爲依賴罷了關係使用TestNG的。

而且除去你給的依賴關係:

<dependency> 
    <groupId>org.apache.maven.surefire</groupId> 
    <artifactId>surefire-testng</artifactId> 
    <version>2.14.1</version> 
</dependency> 
從上面這個

除了正在更像一個集成測試這是maven-failsafe-pluginMaven的萬無一失,插件不工作。

<plugin> 
    <artifactId>maven-failsafe-plugin</artifactId> 
    <executions> 
    <execution> 
     <goals> 
     <goal>integration-test</goal> 
     <goal>verify</goal> 
     </goals> 
    </execution> 
    </executions> 
</plugin> 

這意味着你的測試(基於硒依賴想必集成測試)可以通過運行:

mvn verify 
+0

我沒有你建議的改變(增加了一個插件,POM文件阻止並刪除了萬無一失-testng依賴),但我仍然得到一個異常。雖然這次我得到了一個不同的例外。 – 2013-04-30 13:39:34

+0

製作一個簡單的項目,重現問題並將代碼與POM等放在Github上。 – khmarbaise 2013-04-30 17:46:00

1

我也有過,導致這個錯誤的問題,但對我來說變成缺少將測試運行到測試文件夾的帳戶的文件訪問權限。

可能是要檢查的東西

1

也許會幫助某人。我幫助 - TestNG的變化版本依賴

它是:

<dependency> 
    <groupId>org.testng</groupId> 
    <artifactId>testng</artifactId> 
    <version>6.11</version> 
    <scope>test</scope> 
</dependency> 

並已成爲:

<dependency> 
    <groupId>org.testng</groupId> 
    <artifactId>testng</artifactId> 
    <version>6.10</version> 
    <scope>test</scope> 
</dependency> 
相關問題