2013-05-23 12 views
10

私はマルチモジュールでMavenを使用しています。 3つのプロジェクトがあります。私はすべての依存関係とプラグインfooのポンポンに設定Mavenは単体テストを実行しません

foo(the parent project) 
foo-core 
foo-bar 

<modules> 
    <module>../foo-core</module> 
    <module>../foo-bar</module> 
</modules> 

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.11</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      ... 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.1</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.14.1</version> 
       <dependencies> 
        <dependency> 
        <groupId>org.apache.maven.surefire</groupId> 
        <artifactId>surefire-junit47</artifactId> 
        <version>2.14.1</version> 
        </dependency> 
       </dependencies> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

あり、いくつかの基底クラスとfoo-coreでユニットテストのためのutilのクラスがあるので、私はfoo-coreプロジェクトでmaven-jar-pluginを追加foo-barが利用できるよう:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <version>2.3.1</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>test-jar</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

私はを実行するとゴール、次のような結果が得られました:

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
parallel='none', perCoreThreadCount=true, threadCount=2, useUnlimitedThreads=false 

Results : 

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

私のプロジェクトではテストがあります。しかし、なぜ彼らはそれらのいずれかを実行していないのですか?

+0

に次の設定を追加http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html –

+0

@Grzegorzはい。すべてのテストファイルの名前は、Tests.javaです。 –

+0

もしそうなら、答えを見てください。 –

答えて

15

テストファイルの名前はシュアページに記載されているものに準拠していますか?**Tests.javaから**Test.javaにテストファイルの名前を変更したりpom.xml

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.14.1</version> 
    <configuration> 
    <includes> 
     <include>**/*Tests.java</include> 
    </includes> 
    </configuration> 
</plugin> 
+0

くそー!私はどうしてそんなに盲目的になりますか? –

+1

@キリンヤオ心配しないで!私はすべてのプロジェクトの始めに同じミスをしたので、答えが分かりました。 :-) –

+0

これは私にとっては役に立ちません。私は1つのクラス "OptimizerTest.java"を持っていて、それは完全には何も含まれていませんが、他のクラス "OptimizerTest2.java"は動作しません。私はmvnを実行する場合:test -Dtest = OptimizerTest私は3つのテストが成功したBUILD SUCCESSを受け取りますが、同じコマンドを実行してもOptimizerTest2の場合BUILD FAILUREを受け取り、テストを実行します:0 OptimizerTest2は最初のもののコピーです°_ – Aerox

関連する問題