How can I run a specific test from testng.xml file?

Viewed 151

hope someone help me with this question, thanks !

I have this in testng.xml

<suite name="Test Project" verbose="1" thread-count="1" configfailurepolicy="continue">
    <listeners>
        <listener class-name="com.tests.TestListener"/>
    </listeners>
    <test name="Test1">
        <classes>
            <class name="com.tests.test1.LoginTest1"></class>
        </classes>
    </test>
    <test name="Test2">
        <classes>
            <class name="com.tests.test2.LoginTest2"></class>
        </classes>
    </test>
</suite>

How can I run only the 'Test2'?

I tried mvn test -Dtest=Test2 but it was not working, run both tests

1 Answers

As explained in "maven command to run specific test class got org.testng.TestNGException"

You are mixing the two modes of execution. TestNG lets you run tests in two modes:

  • Via a TestNG suite xml file
  • Individual test classes by specifying the fully qualified class names of them.

In your case, you would need to use the class name of your Test2:

mvn test -Dtest=com.tests.test2.LoginTest2
Related