1, testng, multiple execution of use cases
@Test (Dataprovider = "Data-provider")
Add the parameter source after the @test tag: Dataprovider (Data-provider)
How many sets of data are in the Data-provider, @Test how many times the data will be executed
2, the configuration and use of Dataprovider
@DataProvider (name = "Data-provider") //Iterator iterator protected Iterator<object[]> Testprovider () { Listnew arraylist<object[]>(); Dataorigin.add (new object[]{1,2,3,4}); Dataorigin.add (new object[]{5,6,7,8,}); Dataorigin.add (new object[]{9,10,11,12}); return dataorigin.iterator (); }
When you execute a use case, you pass in a set of data at one time.
@Test (dataprovider= "Data-provider") publicvoid f (intintint int V) { System.out.println (Z+x+c+v); }
Execution results
3. Example
Copy data from Excel, or add additional data
Reading data
@DataProvider (name = "Data-provider") //Iterator iterators protectedIterator<object[]>Testprovider () {List<Object[]> Dataorigin =NewArraylist<object[]>(); Try { for(inti = 1; I < 100; i++) {Dataorigin.add (NewObject[]{redexcel.getexceldata ("D:\\a.xls", 1, I), Redexcel.getexceldata ("D:\\a.xls", 2, I)}); } } Catch(Exception e) {System.out.println ("Data Read complete"); } returnDataorigin.iterator (); }
Execute use case
@Test (dataprovider= "Data-provider") publicvoid f (string URL, string data) { = httprequest.sendpost (URL, data); System.out.println (s); }
Execution results
Interface Test (Java+testng+ant+jenkins) sixth article TestNG II