How do I tell Maven and TestNG to run a specific t

2019-07-26 15:16发布

问题:

I want to be able to run a specific test class from my testng suite using maven. My test classes are dependent on parameters from the testngsuite.xml file. I can run mvn test -DsuiteXmlFile=mysuite.xml or mvn test -Dtest=sometest. Is there any way to combine these two?

This link shows how to do one of the other but not both. How do I tell Maven and TestNG to run either a specific test class or a suite.xml file?

回答1:

Suite files are used to define a test run.

That means if you want only one test, just write a dedicated suite file.



回答2:

you can add to your tesngsuite.xml the following:

<test name="my_test_name">
    <classes>
        <class name="packageName.ClassName" />
    </classes>
</test>

and then run form maven your testngsuite.xml using mvn test -DsuiteXmlFile=testngsuite.xml. Or if you want to your keep your original testngsuite.xml you can just create a copy of it and make modifications there and run from maven your testngsuite2.xml