简体   繁体   中英

How to run a set of classes under single test tag in testng suite?

I have this testng suite segregated under test tag.

This is different interms of other issues ( TestNG surefire, run suite with maven command line ). Here I need to execute set of classes under test tag not specific class nor specific package.

<suite name="Suite1" verbose="1" >
      <test name="set-1" >
        <classes>
           <class name="com.test.ejb.AdminServiceTest" />
           ....
        </classes>
      </test>
      <test name="set-2">
        <classes>
            <class name="com.test.ejb.ServiceTestBase" />
            ...
        </classes>
      </test>
        <test name="set-3">
        <classes>
            <class name="com.test.ejb.RazakIeraTest" />
            ...
        </classes>
      </test>
        <test name="set-4">
        <classes>
            <class name="com.test.ejb.PayCheckTest" />
            ...
        </classes>
      </test>
    </suite>

I have a suite with a grouping of classes under test tag. I would like to execute only one test tag.

We have a way to select single class using this cmd mvn test -Dtest="className" .

I have tried -Dtestnames=set-5 ( http://testng.org/doc/documentation-main.html ). but it did not work.

Do we have any way to execute test tag using maven command ?.

You can use the below command

java -cp ".\bin;.\lib\*;" org.testng.TestNG testng.xml -testnames Test1

you can also provide a list of test names in -testnames parameter

Have a look here

I assume you use maven with maven-surefire-plugin to run your tests, right?

Then in the properties section of the plugin add 'testname' with some variable as a value

<properties>
    <property>
        <name>testnames</name>
        <value>${testng.testnames}</value>
    </property>
</properties>

You can filter your tests by specifying value of the variable

mvn test -Dtestng.testnames=set-1,set-2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM