Automated test group of test cases Deep --TestNg

 

First look at the last chapter, we are talking about a set of tests and use testng.xml file successfully executed test set. So that we understand the test set. There you have to have a collection of groups, today this chapter will talk about the group of test cases.

  TestNG are grouped by keyword group, yes, on this English group. How to achieve it? The old rules, explain in code. Let's start:

  1. Let's build a good class to understand, I'm here now called Groups.

  2. Then grouping, which we attributed to the two test methods "motor vehicle" of the points. The other two methods attributed to the group "communication tool" is. Use the keyword groups and then set the mapping. Code as follows:

package cn.autotest;

 

import org.testng.annotations.Test;

 

public class Groups {

@Test (groups = {"车"})

public void volkswagen (){

System.out.print ( "Volkswagen method called!");

}

@Test (groups = {"车"})

public void ferrari (){

System.out.print ( "Ferrari method called!");

}

@Test (groups = { "phone"})

public void huawei (){

System.out.print ( "Huawei cell phone to call the method!");

}

@Test (groups = { "phone"})

public void iPhone (){

System.out.print ( "Apple phone calls methods!");

}

@Test (groups = { "mobile phone", "car"})

public void carandphone (){

System.out.print ( "method call phone + car!");

}

}

Code Qiaowan old rules, to configure testng.xml files, configuration is as follows:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Suite">

<test name="Groups">

<groups>

<run>

<include name="车"/>

</run>

</groups>

<classes>

<class name="cn.autotest.Groups"/>

</classes>

</test>

</suite>

After configured, run testng.xml file, run the following results:

[TestNG] Running:

  D:\Users\workspace\Autotest\testng.xml

 

Call phone + car method! Ferrari calls the method! Volkswagen calls the method!

=============================================

Suite

Total tests run: 3, Failures: 0, Skips: 0

=============================================

As can be seen from the test results, testng.xml configuration "car" grouping all the testing method is invoked. This way, the test case may be any group. It is not very convenient.

The test group will stop here. Small partners must not be lazy, be sure to follow my previous article, step by step, take the ride environment environment. The knock knock Code Code, so as to learn automation, or deep understanding yo.

Welcome to the King of micro-channel public attention brother automated testing scan code

 

Guess you like

Origin www.cnblogs.com/king44/p/11653278.html