How to exclude class in TestNG?

后端 未结 8 1117
囚心锁ツ
囚心锁ツ 2020-12-30 05:17

Is this possible to exclude classes in testng.xml?

I tried with


    



        
相关标签:
8条回答
  • 2020-12-30 06:00

    I had the same issue ! Anyway, the solution i found is using the tag classes instead of packages this is my testng.xml file :

        <classes>
            <class name="brms.impl.BrmsServicesFactoryTest" />
    <!--            <class name="brms.impl.ServicesFactoryTest" /> -->
        </classes>
    

    in this case, only the class BrmsServicesFactoryTest tests are executed, the other class tests not executed !

    I hope this could help you !

    0 讨论(0)
  • 2020-12-30 06:03

    According to the TestNG dtd, the exclude element is only applicable to the following elements:

    • package - The package description within packages list.
    • methods - The list of methods to include/exclude from this test.
    • run - The subtag of groups used to define which groups should be run.

    The elements classes and class cannot be directly excluded; however, you can exclude classes through groups:

    @Test(groups = { "ClassTest1" })
    public class Test1 {
    
      public void testMethod1() {
      }
    
      public void testMethod2() {
      }
    
    }
    

    Then you will define the testng.xml:

    <suite>
      <test>
        <groups>
          <run>
            <exclude name="ClassTest1"/>
          </run>
        </groups>
        <classes>
          <class name="Test1">
        </classes>
      </test> 
    </suite>
    

    In most cases you define, which classes to include for the run, not to exclude, so just include the classes you want to run.

    0 讨论(0)
提交回复
热议问题