Pallavi Majumder
Pallavi Majumder

Reputation: 33

Mvn test executes all tests correctly however mvn DTest gives error

I have a test case:

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

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

When I run mvn test the test runs perfectly.

However, when I execute

mvn -Dtest=TestCase_1 test_1

I get the following error:

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.

Does anyone have any idea how to resolve this. I have tried specifying lifecycle goals but it still results in the same error.

Upvotes: 0

Views: 226

Answers (1)

hiroyukik
hiroyukik

Reputation: 814

You have to execute your test as below commands:

All test case:

mvn test

Specify test case:

mvn -Dtest=TestCase_1 test

if you have the library 'maven-surefire-plugin' which version is 2.7.3 or later. you can specify the specific method

mvn -Dtest=TestCase_1#test_1 test

Please try them.

Upvotes: 1

Related Questions