Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

testng.xml

1. With bag and without bag

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

2. The specified package does not specify the class

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

In the above case, TestNG will look at all the classes in the package test.sample and will only execute the classes with TestNG annotations.

3. Specify the groups and methods to include and exclude

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

In the above case, if groups="checkinTests" is configured in @Test, it will be executed, and if groups="brokenTests" is not configured or configured, it will not be executed.

In the IndividualMethodsTest class, only testMethod will be executed.

4. Disrupt the execution order

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

By default, TestNG will run the tests in the order found in the XML file.

If you want to run the classes and methods listed in this file in an unpredictable order, set the preserve-order property to false.

Test class, test method, test group

1. Execute the method with return value

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

By default, if the method using @Test has a return value, it will be ignored directly, and it can be executed after using allow-return-values="true".

2、Test groups

TestNG allows you to perform complex grouping of test methods.

Not only can you declare that a method belongs to a group, you can also specify a group that contains other groups.

You can then call TestNG and ask it to include a specific group (or regular expression), while excluding another group.

If you want to run two different sets of tests in succession, this will provide you with the greatest flexibility to divide the test methods, and you don't need to recompile anything.

3. Combination usage

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

In the above case, testMethod1, testMethod2, and testMethod3 will be executed. When <include name="functest"/><include name="checkintest"/>, only testMethod1 and testMethod2 will be executed.

4. Regular expression usage

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

In the above case, only the methods starting with groups=windows will be executed.

5. Method inclusion and exclusion

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

In the above case, if the method name is matched individually, if the method name contains enabledTestMethod, the method will be executed, and if the method contains brokenTestMethod, it will not be executed.

This method is not recommended, because it will change your method name.

6, the nested definition of the group

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

In the above case, all includes checkintest and function, function includes window and linux, and finally runs all.

As long as the method uses all or all groups included, it will be executed.

7, have include and exclude at the same time

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

In the above case, the testMethod2 method has both include checkintest and exclude broken, then this method will not be executed. Using this method allows us to temporarily disable certain methods without affecting the original configuration .

When you want to continue to use these methods, you only need to remove the broken.

8. Use grouping on classes

Let’s be honest: I’ve never thought that automated use case management would be so elegant before I used testng.

 

In the above case, method1 and method2 belong to the checkin-test group, and method1 also belongs to the func-test group.

When the checkin-test group is running, both method1 and method2 will run. When the func-test group is allowed, only method1 will be run.

Recommend a software testing learning exchange group: 785128166, there are shared videos, interview guidance, test materials, mind maps, and videos in the group. They are all dry goods, you can download and watch. Mainly share test foundation, interface test, performance test, automated test, TestOps architecture, Jmeter, LoadRunner, Fiddler, MySql, Linux, resume optimization, interview skills, and actual video data of large-scale test projects. Use every minute and every second of your time to learn to improve yourself, and don't use "no time" to conceal your mental laziness! Try hard while you are young, and give your future self an explanation!

Public number: Programmer Erhei, after paying attention, you can receive a large amount of learning materials for free.

Good things should be shared with friends
 

Guess you like

Origin blog.csdn.net/m0_52668874/article/details/114758305