Mvn测试正确执行所有测试,但mvn DTest给出错误

时间:2017-02-06 10:47:33

标签: java maven testing

我有一个测试用例:

import org.graph.*;
import org.junit.*;

public class TestCase_1
{
    @Test
    public void test_1() {
      System.out.println("Hello World");
      new A().bat();
    }
}

当我运行mvn test时,测试运行完美。

然而,当我执行

mvn -Dtest=TestCase_1 test_1

我收到以下错误:

Unknown lifecycle phase "test_1". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy.

有没有人知道如何解决这个问题。我已经尝试过指定生命周期目标,但它仍会导致相同的错误。

1 个答案:

答案 0 :(得分:1)

您必须按以下命令执行测试:

所有测试用例:

mvn test

指定测试用例:

mvn -Dtest=TestCase_1 test

如果你有图书馆&#39; maven-surefire-plugin&#39;哪个版本是2.7.3或更高版本。 您可以指定具体方法

mvn -Dtest=TestCase_1#test_1 test

请试试。

相关问题