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

◇◆丶佛笑我妖孽 提交于 2020-01-06 05:40:05

问题


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 ?.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/47436748/how-to-run-a-set-of-classes-under-single-test-tag-in-testng-suite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!