Reputation: 21
I've changed the junit version from 3.8 to 4.4 in the application use maven 1. For that I change the project.xml, now look like this:
...
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<properties>
<scope>test</scope>
</properties>
</dependency>
...
I add some tests using annotations like @Test or @Before and those tests run perfect in eclipse. When I try to run "maven test" in console I get the following output:
test:compile:
[junit] Running com.myapp.Class1Test
[junit] Tests run: 6, Failures: 0, Errors: 0, Time elapsed: 0.721 sec
[junit] Running com.myapp.Class2Test
[junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 1.16 sec
[junit] Running com.myapp.Class3Test
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.538 sec
[junit] [ERROR] Test com.myapp.Class3Test FAILED
[junit] Running com.myapp.Class4Test
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.565 sec
[junit] [ERROR] Test com.myapp.Class4Test FAILED
[junit] Running com.myapp.Class5Test
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.565 sec
[junit] [ERROR] Test com.myapp.Class5Test FAILED
[junit] Running com.myapp.Class6Test
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.691 sec
[junit] [ERROR] Test com.myapp.Class6Test FAILED
[junit] Running com.myapp.Class7Test
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.549 sec
[junit] [ERROR] Test com.myapp.Class7Test FAILED
[junit] Running com.myapp.Class8Test
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.708 sec
[junit] [ERROR] Test com.myapp.Class8Test FAILED
[junit] Running com.myapp.Class9Test
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.643 sec
[junit] [ERROR] Test com.myapp.Class9Test FAILED
[junit] Running com.myapp.Class10Test
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.668 sec
[junit] [ERROR] Test com.myapp.Class10Test FAILED
[junit] Running com.myapp.Class11Test
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.644 sec
[junit] [ERROR] Test com.myapp.Class11Test FAILED
[echo]
==========================================================
WARNING: There were test failures!
==========================================================
The test files that fail have more than one test inside. Maven just doesn't see them. Also when I use maven in debug I see that it loads implicit junit 3.8.
That's why I think somehow the old junit jar is been used. I just don't know where or how to detect it.
Any help, advise, ray of light will be appreciated.
Upvotes: 2
Views: 205
Reputation: 11
Try this:
Add an adapter in your tests :
/**
* @return instance of this as Junit test case
*/
public static junit.framework.Test suite ()
{
return new JUnit4TestAdapter(IntTestSpringCoherency.class);
}
Taken from: http://maven.40175.n5.nabble.com/Can-maven-1-x-run-Junit-4-tests-td92773.html
Upvotes: 1
Reputation: 21
A possible solution/workaround:
public void AClassUnitTest {
public static junit.framework.Test suite ()
{
return new JUnit4TestAdapter(AClassUnitTest.class);
}
@Test
public method_income_expected(){
...
}
}
Thanks!
Upvotes: 0
Reputation:
try using the latest one (though it in itself probably won't fix your issue here), also use
mvn -X clean test
and include the stactrace in your original post.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
You can also look at the output produced by the following and exclude the junit 3.8 jar
mvn dependency:tree
Upvotes: 2
Reputation: 5867
I'm not aware of the <properties>
element with a scope having any meaning in the way you've used it, unless another plugin needed it. It looks like you've tried to force a Maven 2 concept into Maven 1.
You could try setting the maven.test.classpath
property to help it pick up the JUnit JAR. I don't make any guarantees about this working - JUnit 4 was never supported in Maven 1.x, and Maven 1.x has not been actively developed for over 4 years now. As you'll see, all the other responders are answering with answers only relevant to Maven 2 - you should strongly consider updating your build.
Upvotes: 3
Reputation: 2260
Try finding out why its loading junit 3.8. You can use mvn dependency:tree and then based on the result exclude it specifically.
Upvotes: 3