2012-02-17 72 views
2

我們使用Maven 3.0.3,並使用JUnit 4.8.1 ...如何在Maven中運行單個測試?

<dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.1</version> 
     <scope>test</scope> 
    </dependency> 

我們有這個測試文件...

./src/test/java/com/myco/clearing/common/xml/TextNodeTest.java 

我怎樣才能運行這個單獨的測試?當我嘗試

mvn -Dtest=TextNodeTest test 

我得到一個錯誤,說沒有測試運行。如果我將完整的軟件包名稱指定給我的測試,我會得到相同的錯誤。 ...

mvn clean -Dtest=com.myco.clearing.common.xml.TextNodeTest test 

產生的錯誤信息......

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project myco-productplus-web: No tests were executed! 
(Set -DfailIfNoTests=false to ignore this 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 

這裏是我使用

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.12</version> 
      <configuration> 
       <skip>false</skip> 
       <additionalClasspathElements> 
        <additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement> 
        <additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement> 
       </additionalClasspathElements> 
       <useManifestOnlyJar>false</useManifestOnlyJar> 
       <forkMode>always</forkMode> 
       <systemProperties> 
        <property> 
         <name>gwt.args</name> 
         <value>-out "${webappDirectory}"</value> 
        </property> 
       </systemProperties> 
       <systemPropertyVariables> 
        <tomcat.port>${tomcat.servlet.port}</tomcat.port> 
        <project.artifactId>${project.artifactId}</project.artifactId> 
       </systemPropertyVariables> 
      </configuration> 
     </plugin> 
+0

戴夫,做了降級到2.11的工作? – 2012-02-22 05:36:29

回答

2

看起來就像是一個錯誤在2.12版本中萬無一失配置 - SUREFIRE-827。嘗試降級到2.11。

5

運行在萬無一失的單個測試(法)的方法是做:

mvn test -Dtest=uk.co.farwell.AppTest#testSlow 

注意#,而不是類名和方法名之間的空間。

然而,隨着@Andrew表示,目前在2.12(SUREFIRE-827: Surefire 2.12 cannot run a single test, regression from 2.11)中的錯誤,但它在2.11的作品。

上述錯誤仍然是打開的(截至2012年2月24日),但實際上對我使用2.13-SNAPSHOT。

編輯:現在在2.12.1中標記爲固定。

0

像其他人說的那樣,這是Surefire中的一個錯誤,並且從2.11.1版本開始固定

相關問題