Maven: Spring-Test 2.5.x & JUnit 4

I ran into this weird problem today while setting up an integration-testing module in my maven project: The Surefire-plugin seemed to ignore the JUnit4 annotations.
I found a Maven-Surefire issue (SUREFIRE-448) describing the same problem, but it is marked as irreproducible and proposes no solution.
After looking into the debug information (mvn clean test -X > log.txt), it turns out that Spring-Test has a dependency on JUnit 3.8.1, and this is causing my test classes to run as JUnit3 instead of JUnit4.
To fix this, simply exclude JUnit from the Spring-Test dependency:

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>2.5.6</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>

No comments:

Post a Comment