使用`mvn test`参数化JUnit测试是否正确? [英] Does Parameterized JUnit test correct with `mvn test`?
问题描述
我刚刚使用 JUnit实现了一个JUnit测试用例
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
我使用
<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>
此测试案例:
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() {
}
}
但当我使用 mvn test
进行测试时,maven说:
But when I test it using mvn test
, maven said:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
如何使其有效?
推荐答案
问题是maven的命名约定基于 maven-surefire -plugin
需要命名,如 Test.java ,测试 .java 或 TestCase *。 java 用于单元测试。对于集成测试, maven-failsafe-plugin 负责,其命名惯例为 IT * .java , * IT.java 或 * ITCase.java 。
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.
这篇关于使用`mvn test`参数化JUnit测试是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!