A, TestNg data driver
1. The data driver
1) What is a data-driven?
· Data-driven means that in the case where a fixed script, script data to control whether the operation, and the number of runs, each run as well as the corresponding parameters
2) data-driven application scenarios:
· For example, we tested logged in to be tested with a different account login, do we need to write a script for each account yet? This is clearly unwise, then, testng provided us with this footnote, so we only need to provide the data, you can control the number of script runs and the corresponding parameters.
2. TestNg data driver (a data source)
1) implementation:
• Use footnote: @DataProvider
2) Example:
The first implementation: Not specified name
operation result:
The second way: Specify name
operation result:
Two, TestNg run with XML
TestNg several operating modes:
1. method starting point
<?xml version="1.0" encoding="UTF-8"?> <suite name="Suite" verbose="1" parallel="false" thread-count="1"> <test name="test1"> <classes> <class name="com.test.ng1.test1"> <methods> <include name="test2"/> <include name="test1"/> </methods> </class> </classes> </test> </suite>
operation result:
2. anchored to class
<?xml version="1.0" encoding="UTF-8"?> <suite name="Suite" verbose="1" parallel="false" thread-count="1"> <test name="test1"> <classes> <class name="com.test.ng1.test1"> </class> </classes> </test> </suite>
operation result:
3. package starting point
<?xml version="1.0" encoding="UTF-8"?> <suite name="Suite" verbose="1" parallel="false" thread-count="1"> <test name="test1"> <packages> <package name="com.test.ng1"/> </packages> </test> </suite>
Three, TestNg Use Case Management
Example 1. management principles - Example independently with less dependence
com.test.ng1 Package; Import org.testng.annotations.BeforeClass; Import org.testng.annotations.BeforeMethod; Import org.testng.annotations.DataProvider; Import org.testng.annotations.Test; Import org.testng.annotations. AfterClass; Import org.testng.annotations.AfterMethod; public class test1 { // data driver unknown, can call a method on the @dataProvider public Object [] [] logindata () { return new new Object [] [] {{ "a "}, {" B "}}; } // because no data driver name, a method name can be written easily found @Test (the dataProvider =" logindata ") public void test1 (String info) { System.out.println (info) ; } // the name of the data driver is defined @DataProvider (name = "longoutdata") public Object [] [] logoutDataInfo ( ) { return new Object[][]{{"1"},{"2"}}; } //指定数据驱动的名字,而非方法名 @Test(dataProvider="longoutdata") public void test2(String info){ System.out.println(info); } @BeforeClass public void bClass(){ System.out.println("BeforeClass"); } @AfterClass public void aClass(){ System.out.println("AfterClass"); } @BeforeMethod public void setUp(){ System.out.println("beforemethod,setUp"); } @AfterMethod public void tearDown(){ System.out.println("aftermethod,tearDown"); } }
----------------
Disclaimer: This article is CSDN blogger "jffhy2017 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/jffhy2017/article/details/60972253