• TestNG关键字和testNG.xml结构学习


    转自官网:http://testng.org/doc/documentation-main.html#test-results

    TestNG关键字

    @BeforeSuite
    @AfterSuite
    @BeforeTest
    @AfterTest
    @BeforeGroups
    @AfterGroups
    @BeforeClass
    @AfterClass
    @BeforeMethod
    @AfterMethod

    @BeforeSuite: The annotated method will be run before all tests in this suite have run. 
    @AfterSuite: The annotated method will be run after all tests in this suite have run. 
    @BeforeTest: The annotated method will be run before any test method belonging

    to the classes inside the <test> tag is run. 
    @AfterTest: The annotated method will be run after all the test methods belonging 

    to the classes inside the <test> tag have run. 
    @BeforeGroups: The list of groups that this configuration method will run before. 

    This method is guaranteed to run shortly before the first test method that belongs 

    to any of these groups is invoked.
    @AfterGroups: The list of groups that this configuration method will run after. 

    This method is guaranteed to run shortly after the last test method that belongs

     to any of these groups is invoked. 
    @BeforeClass: The annotated method will be run before the first test method in 

    the current class is invoked. 
    @AfterClass: The annotated method will be run after all the test methods in the 

    current class have been run. 
    @BeforeMethod: The annotated method will be run before each test method. 
    @AfterMethod: The annotated method will be run after each test method.

    testNG.xml结构

    The concepts used in this documentation are as follows:

    • A suite is represented by one XML file. It can contain one or more tests and is defined by the <suite> tag.
    • A test is represented by <test> and can contain one or more TestNG classes.
    • A TestNG class is a Java class that contains at least one TestNG annotation. It is represented by the <class> tag and can contain one or more test methods.
    • A test method is a Java method annotated by @Test in your source.

    Here is an example testng.xml file:

    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
     
    <suite name="Suite1" verbose="1" >
      <test name="Nopackage" >
        <classes>
           <class name="NoPackageTest" />
        </classes>
      </test>
    
      <test name="Regression1">
        <classes>
          <class name="test.sample.ParameterSample"/>
          <class name="test.sample.ParameterTest"/>
        </classes>
      </test>
    </suite>
     

    You can specify package names instead of class names:

    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
    
    <suite name="Suite1" verbose="1" >
      <test name="Regression1"   >
        <packages>
          <package name="test.sample" />
       </packages>
     </test>
    </suite>
     

    In this example, TestNG will look at all the classes in the package test.sample and will retain only classes that have TestNG annotations.

    You can also specify groups and methods to be included and excluded:

    public class Test1 {
      @Test(groups = { "functest", "checkintest" })
      public void testMethod1() {
      }
    
      @Test(groups = {"functest", "checkintest"} )
      public void testMethod2() {
      }
    
      @Test(groups = { "functest" })
      public void testMethod3() {
      }
    }


    <test name="Regression1">
      <groups>
        <run>
          <exclude name="brokenTests"  />
          <include name="checkinTests"  />
        </run>
      </groups>
     
      <classes>
        <class name="test.IndividualMethodsTest">
          <methods>
            <include name="testMethod" />
          </methods>
        </class>
      </classes>
    </test>
     

    You can also define new groups inside testng.xml and specify additional details in attributes, such as whether to run the tests in parallel, how many threads to use, whether you are running JUnit tests, etc... 

    
    

    By default, TestNG will run your tests in the order they are found in the XML file. If you want the classes and methods listed in this file to be run in an unpredictible order, set the preserve-order attribute to false

    <test name="Regression1" preserve-order="false">
      <classes>
    
        <class name="test.Test1">
          <methods>
            <include name="m1" />
            <include name="m2" />
          </methods>
        </class>
    
        <class name="test.Test2" />
    
      </classes>
    </test>
     

    Please see the DTD for a complete list of the features, or read on.

  • 相关阅读:
    个人永久性免费-Excel催化剂功能第43波-文本处理类函数增强
    个人永久性免费-Excel催化剂功能第42波-任意字符指定长度随机函数
    个人永久性免费-Excel催化剂功能第41波-文件文件夹相关函数
    个人永久性免费-Excel催化剂功能第40波-工资、年终奖个人所得税计算函数
    个人永久性免费-Excel催化剂功能第39波-DotNet版的正则处理函数
    安装的SQL Server2008 R2版的连接不到本地数据,提示未找到或无法访问服务器。----复制自百度知道
    System.Web.mail ----虚拟发件人发送邮件
    chosen.jquery.min.js select2.js 弊端
    web打印
    用window.print()打印如何去掉页眉和页脚
  • 原文地址:https://www.cnblogs.com/digod/p/5832264.html
Copyright © 2020-2023  润新知