使用`mvn test`参数化JUnit测试是否正确?

jac*_*ope 3 java junit maven

我刚刚JUnit在示例后面使用4.11 实现了一个JUnit测试用例:

https://github.com/junit-team/junit/blob/master/doc/ReleaseNotes4.11.md#example-1

我使用创建一个maven项目

<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>
Run Code Online (Sandbox Code Playgroud)

而这个测试用例:

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() {
      }
}
Run Code Online (Sandbox Code Playgroud)

但当我使用它进行测试时mvn test,maven说:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
There are no tests to run.
Run Code Online (Sandbox Code Playgroud)

如何使它工作?

khm*_*ise 10

问题是maven的命名约定,它基于maven-surefire-plugin ,需要命名如Test.java,Test .javaTestCase*.java进行单元测试.对于集成测试,maven-failsafe-plugin负责具有IT*.java,*IT.java*ITCase.java的命名约定.