patternjavaCritical
Maven does not find JUnit tests to run
Viewed 0 times
runmavenfindjunitdoesnottests
Problem
I have a maven program, it compiles fine. When I run
I've recreated this problem with a super simple setup which I will include below as well as the output when run with
The unit tests run fine from eclipse (both with its default junit package and when I instead include the junit.jar downloaded by maven). Also mvn
Here is the directory structure:
pom.xml:
ClassUnderTest.java:
ClassUnderTestTests.java:
End of mvn -X test:
```
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-surefire-plugin:2.7.1:test from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-surefire-plugin:2.7.1, parent: sun.misc.Launcher$AppClassLoa
mvn test it does not run any tests (under TESTs header says There are no tests to run.). I've recreated this problem with a super simple setup which I will include below as well as the output when run with
-X.The unit tests run fine from eclipse (both with its default junit package and when I instead include the junit.jar downloaded by maven). Also mvn
test-compile correctly creates the class under test-classes. I am running this on OSX 10.6.7 with Maven 3.0.2 and java 1.6.0_24.Here is the directory structure:
/my_program/pom.xml
/my_program/src/main/java/ClassUnderTest.java
/my_program/src/test/java/ClassUnderTestTests.javapom.xml:
4.0.0
my_group
my_program
jar
1.0-SNAPSHOT
My Program
junit
junit
4.8.1
test
org.apache.maven.plugins
maven-compiler-plugin
1.5
1.5
ClassUnderTest.java:
public class ClassUnderTest {
public int functionUnderTest(int n) {
return n;
}
}ClassUnderTestTests.java:
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class ClassUnderTestTests {
private ClassUnderTest o;
@Before
public void setUp() {
o = new ClassUnderTest();
}
@Test
public void testFunctionUnderTest_testCase1() {
Assert.assertEquals(1, o.functionUnderTest(1));
}
@Test
public void testFunctionUnderTest_testCase2() {
Assert.assertEquals(2, o.functionUnderTest(2));
}
}End of mvn -X test:
```
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-surefire-plugin:2.7.1:test from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-surefire-plugin:2.7.1, parent: sun.misc.Launcher$AppClassLoa
Solution
By default Maven uses the following naming conventions when looking for tests to run:
If your test class doesn't follow these conventions you should rename it or configure Maven Surefire Plugin to use another pattern for test classes.
Test*
*Test
*Tests(has been added in Maven Surefire Plugin 2.20)
*TestCase
If your test class doesn't follow these conventions you should rename it or configure Maven Surefire Plugin to use another pattern for test classes.
Context
Stack Overflow Q#6178583, score: 805
Revisions (0)
No revisions yet.