I'm just implemented a JUnit test case using JUnit
4.11 following the example:
https://github.com/junit-team/junit/blob/master/doc/ReleaseNotes4.11.md#example-1
I create a maven project using
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yyt</groupId>
<artifactId>example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
And this test case:
import java.util.Arrays;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class Example {
@Parameters(name = "{index}: fib({0})={1}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][] { { 0, 0 }, { 1, 1 }, { 2, 1 },
{ 3, 2 }, { 4, 3 }, { 5, 5 }, { 6, 8 } });
}
private int input;
private int expected;
public Example(int input, int expected) {
this.input = input;
this.expected = expected;
}
@Test
public void test() {
}
}
But when I test it using mvn test
, maven said:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
How to make it work?
The problem is the naming convention of maven which is based on maven-surefire-plugin which needs a naming like Test.java, Test.java or TestCase*.java for unit tests. For integration tests the maven-failsafe-plugin is responsible which has the naming convention IT*.java, *IT.java or *ITCase.java.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With