jamesdeath123
jamesdeath123

Reputation: 4606

mvn unable to execute testNG classes in custom location from terminal

Given a folder structure:

theProject/src/com/myclass/tests/api/APITest

where the package declaration is:

package com.myclass.tests.api;

And it uses @Test from testng.

In pom.xml, I have included the build section:

<build>
    <testSourceDirectory>${project.basedir}/</testSourceDirectory>
     <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.19.1</version>
          <configuration>
                    <includes>
                        <include>**/*Test.class</include>
                        <include>**/*test.class</include>
                        <include>src/com/myclass/tests/api/*Test.class</include>
                    </includes>
                </configuration>
        </plugin>
    </plugins>
  </build>

I tried to execute the following command in the theProject folder (that the pom.xml locates).

mvn test -Dtest=com.myclass.tests.api.*

but the results gives:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project theProject: No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]

How should I run the test from mvn?

Upvotes: 0

Views: 28

Answers (1)

Scorpio
Scorpio

Reputation: 2327

I don't think

 <testSourceDirectory>${project.basedir}/</testSourceDirectory>

is what you want then.

Try

<testSourceDirectory>${project.basedir}/src</testSourceDirectory>

instead.

Reasoning: Maven does not find the folder structure

/com/myclass/tests/api

which would be the result of the package structure (of your test) within ${project.basedir}, so it does not find your tests and fails. The extra src folder needs to be adressed.

Upvotes: 1

Related Questions