0
votes

When I try to run a single TestNG test class from the command line using the command

mvn test -Dtest=NBC1

where NBC1 is the name of my test class, I get an error message saying "Failed to execute goal... No tests wre executed!

I am running this using Java. My current configuration is that I have one master testng.xml suite file in my project root. I have this listed in my POM file as an XmlSuiteFile. This testng.xml file contains other suite files which contain the actual test classes. I have tried moving these out and not nesting my suite files, but it still does not work. Each test class contains only 1 test method.

Here is where I specify my top-level suite file

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M3</version>     
    <configuration>
        <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
</plugin>

And this is what my suite file looks like

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name = "Test Suite">
    <listeners>
        <listener class-name="com.project.selenium.utilities.AnnotationTransformer" />
    </listeners>
    <suite-files>
        <suite-file path="src/main/java/com/project/selenium/testsuites/foo1/FullSuite.xml"    />
        <suite-file path="src/main/java/com/project/selenium/testsuites/foo2/FullSuite.xml" />
    </suite-files>
</suite>

This is what one of the FullSuite.xml files looks like. I've left off some suite-files for simplicity's sake

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="AssureTrak Full Suite">
    <suite-files>
        <suite-file path="src/main/java/com/project/selenium/testsuites/foo1/Cleanup.xml"              />
        <suite-file path="src/main/java/com/project/selenium/testsuites/foo1/DataSetup.xml"            />
</suite-files>
</suite>

And, finally, this is a lowest level suite file looks like

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name = "DataSetup">
    <test name = "DataSetup">
        <classes>
            <class name="com.project.selenium.testcases.foo1.datasetup.nbc.NBC1" />
            <class name = "com.project.selenium.testcases.foo1.datasetup.nbc.NBC2" />
            <class name = "com.project.selenium.testcases.foo1.datasetup.nbc.NBC3" />
            <class name = "com.project.selenium.testcases.foo1.datasetup.nbc.NBC4" />
            <class name = "com.project.selenium.testcases.foo1.datasetup.nbc.NBC5" />
        </classes>
    </test>
</suite>
1

1 Answers

0
votes
  1. Try upgrading to the latest version of TestNG as you might be suffering from a form of a bug
  2. Try providing fully qualified class name like

    mvn -Dtest=com.project.selenium.testcases.foo1.datasetup.nbc.NBC1 test
    
  3. You can always come up with a testng.xml file to kick off the desired class like:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="TestNG Debug Single Class">
        <test name="testng">
            <classes>
                <class name="com.project.selenium.testcases.foo1.datasetup.nbc.NBC1"/>
            </classes>
        </test>
    </suite> 
    

    however if points 1 and 2 will not help it looks like a bug so you could report it

Check out example TestNG integration instruction for more information