TestNG learning-testng.xml

1. Introduction to testing.xml

TestNG can be invoked in several different ways:

使用一个testng.xml文件使用ant使用命令行

Let's mainly look at the format of testng.xml, as an example:

<!DOCTYPE suite SYSTEM "https://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>

It is also possible to specify a package name instead of a class name:​​​​​​​​

<!DOCTYPE suite SYSTEM "https://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 classes in package test.sample and will only keep the classes with TestNG annotations. You can also specify groups and methods to include and exclude:​​​​​​​​

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

It is also possible to define new groups in testng.xml and specify other details in properties such as whether to run tests in parallel, how many threads to use, whether JUnit tests are being run, etc.

By default, TestNG will run the tests in the order they are found in the XML file. If you want the classes and methods listed in this file to run in an unpredictable 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>

 

2. Create testng.xml in idea

1) Install testng, directly adopt the form of maven dependency, and add it into pom.xml:​​​​​​​​

<repositories>  <repository>    <id>jcenter</id>    <name>bintray</name>    <url>https://jcenter.bintray.com</url>  </repository></repositories> <dependency>  <groupId>org.testng</groupId>  <artifactId>testng</artifactId>  <version>7.1.0</version>  <scope>test</scope></dependency>
注:version的版本可以自己选择(https://github.com/cbeust/testng-eclipse)

2) Install Create TestNG XML

IntelliJ IDEA -> Preferences -> Plugins 

    Search testng as shown in the picture

picture

3) Right-click on your own project and select create testng xml. The pro-test may be delayed.

picture

    After that, you can try some preliminary operations.

    Welcome to pay attention to my official account [Test Memo], view more original content, and communicate more~

 

Guess you like

Origin blog.csdn.net/hashsabr/article/details/113801123