0

別の投稿のすべてのアドバイスを試した後でも、Maven Surefire に JUnit 4 テストを実行させることができません。

私のPOM:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>maven-test</groupId>
  <artifactId>maven-test</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>org.junit</groupId>
      <artifactId>com.springsource.org.junit</artifactId>
      <version>4.4.0</version>
      <scope>test</scope>
    </dependency>  
  </dependencies>

  <build> 
    <plugins> 
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>  
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.5</version>
      </plugin> 
    </plugins>
  </build> 
</project>

私のテスト:

public class TestSimple {

 public void testSurePass()
 {
  int x = 1;
  Assert.assertEquals(1, x);
 }

 @Test
 public void surePass()
 {
  int x = 1;
  Assert.assertEquals(1, x);  
 }
}

Surefire は testSurePass を取得しましたが、surePass を確認したことはありません。mvn -X を試しました:

[INFO] [surefire:test {execution: default-test}]
[DEBUG] dummy:dummy:jar:1.0 (selected for null)
[DEBUG]   org.apache.maven.surefire:surefire-booter:jar:2.5:runtime (selected for runtime)
[DEBUG]     org.apache.maven.surefire:surefire-api:jar:2.5:runtime (selected for runtime)
[DEBUG] Adding to surefire booter test classpath: C:\Users\.m2\repository\org\apache\maven\surefire\surefire-booter\2.5\surefire-booter-2.5.jar
[DEBUG] Adding to surefire booter test classpath: C:\Users\.m2\repository\org\apache\maven\surefire\surefire-api\2.5\surefire-api-2.5.jar
[DEBUG] dummy:dummy:jar:1.0 (selected for null)
[DEBUG] Retrieving parent-POM: org.apache.maven.surefire:surefire-providers:pom:2.5 for project: null:surefire-junit:jar:null from the repository.
[DEBUG] Adding managed dependencies for unknown:surefire-junit
[DEBUG]   org.apache.maven.surefire:surefire-api:jar:2.5
[DEBUG]   org.apache.maven.surefire:surefire-booter:jar:2.5
[DEBUG]   org.codehaus.plexus:plexus-utils:jar:1.5.9
[DEBUG]   org.apache.maven.surefire:surefire-junit:jar:2.5:test (selected for test)
[DEBUG]     junit:junit:jar:3.8.1:test (selected for test)
[DEBUG]     org.apache.maven.surefire:surefire-api:jar:2.5:test (selected for test)
[DEBUG] Adding to surefire test classpath: C:\Users\.m2\repository\org\apache\maven\surefire\surefire-junit\2.5\surefire-junit-2.5.jar
[DEBUG] Adding to surefire test classpath: C:\Users\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar
[DEBUG] Adding to surefire test classpath: C:\Users\.m2\repository\org\apache\maven\surefire\surefire-api\2.5\surefire-api-2.5.jar
[DEBUG] Test Classpath :
[DEBUG]   C:\Workspace\tests\maven-test\target\test-classes
[DEBUG]   C:\Workspace\tests\maven-test\target\classes
[DEBUG]   C:\Users\.m2\repository\org\junit\com.springsource.org.junit\4.4.0\com.springsource.org.junit-4.4.0.jar
[DEBUG] Setting system property [user.dir]=[C:\Workspace\tests\maven-test]
[DEBUG] Setting system property [localRepository]=[C:\Users\.m2\repository]
[DEBUG] Setting system property [basedir]=[C:\Workspace\tests\maven-test]

Surefire 2.5 は、junit-3.8.1 をテスト クラスパスに自動的に追加します。junit-4.4.0 も追加されていますが (クラスパスを確実にテストするためではなく、クラスパスをテストするため)、junit-3.8.1 が優先されるようです。Maven の Surefire-api プロジェクトは、 http://maven.apache.org/surefire/surefire-providers/dependencies.htmlによると、junit-3.8.1 に依存しています。

ここにいくつかの設定がありませんか?

4

4 に答える 4

3

Surefire には、springsource によってパッケージ化された junit アーティファクトを使用してだまされている junit バージョンのアーティファクト検出メカニズムがあります。junitartifactname パラメータ を org.junit:com.springsource.org.junitに設定する必要があります

于 2010-02-02T10:14:22.747 に答える
3

問題を再現できません。しかし、実際には Jira の問題 ( EBR-220を参照) があり、SpringSource によってパッケージ化された JUnit アーティファクトを使用する場合、確実な構成に以下を追加する必要があることを説明しています。

<junitArtifactName>org.junit:com.springsource.org.junit</junitArtifactName>
于 2010-02-02T10:15:10.983 に答える
1

Maven 1.x で JUnit 4.x を使用することは可能です:

* add Junit 4.X in your dependencies
* Use the JUnit4TestAdapter in your test classes :
  /**

* @return instance of this as Junit test case
  */
  public static junit.framework.Test suite() { return new JUnit4TestAdapter(MyTestClass.class); }

* run maven with a jdk >= 5
于 2010-08-20T06:53:36.550 に答える
0

これを確認してみてください: JUnit + Maven + Eclipse: @BeforeClass が機能しないのはなぜですか?

于 2011-05-29T15:28:22.963 に答える