How to execute specific test classes from testng.x

2019-09-10 15:52发布

问题:

  <?xml version="1.0" encoding="UTF-8"?>
  <suite name="AutomationTestSuite" allow-return-values="true"  verbose="10" >
    <test name="Login">
      <classes>
         <class name="com.proj.tests.Login" />
      </classes>
    </test>
    <test name="OpenandEdit">
      <classes>
         <class name="com.proj.tests.OpenandEdit" />
      </classes>
    </test> 
     <test name="CasesGroup">
       <groups>
         <run>
           <class name="CasesMenu"/>
           <class name="CasesExport"/>
         </run>
       </groups>  
     </test>

Given above is the testng.xml file which has all classes listed. How do i run only test classes in groups tag. or is there any other way we can execute selected set of test classes from testng.xml file.

回答1:

Comment out Login and OpenandEdit Test Classes and Run as TestNG



回答2:

How do i run only test classes in groups tag

By specifying the group you want to run.

...
<test name="Regression1">
  <groups>
    <run>
      <exclude name="brokenTests"  />
      <include name="checkinTests"  />
    </run>
  </groups>
</test>
...

To run, just Right Click+Run as TestNG Suite