Infallibile non raccoglie Junit 4 prove
Domanda
Non riesco a Maven Surefire per eseguire i miei test JUnit 4 anche dopo che ho provato tutti i consigli da un altro post.
Il mio 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>
La mia prova:
public class TestSimple {
public void testSurePass()
{
int x = 1;
Assert.assertEquals(1, x);
}
@Test
public void surePass()
{
int x = 1;
Assert.assertEquals(1, x);
}
}
infallibile raccolse testSurePass, ma non ha mai visto surePass. Ho provato 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]
infallibile 2.5 aggiunge JUnit-3.8.1 al suo percorso di classe di test automaticamente. Anche se anche si aggiunge JUnit-4.4.0 (per non infallibile prova classpath, ma prova Classpath), JUnit-3.8.1 sembra avere la precedenza. progetto infallibile-API di Maven ha una dipendenza da JUnit-3.8.1 in base alle http: //maven.apache.org/surefire/surefire-providers/dependencies.html.
Mi sto perdendo un po 'di configurazione qui?
Soluzione
infallibile ha un JUnit versione artefatto mechanim rilevamento che viene ingannato da voi utilizzando l'artefatto JUnit confezionato da SpringSource. È necessario impostare la junitartifactname parametro a org.junit: com.springsource.org.junit
Altri suggerimenti
Mi sono perso, non in grado di riprodurre il problema. Ma c'è davvero un problema Jira (vedi EBR-220 ) spiegando che è necessario aggiungere il seguente alla configurazione infallibile quando si usa l'artefatto JUnit confezionato da SpringSource:
<junitArtifactName>org.junit:com.springsource.org.junit</junitArtifactName>
E 'possibile utilizzare JUnit 4.x con Maven 1.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
Prova a controllare questo: JUnit + Maven + eclipse: Perché @BeforeClass non funziona