Interface Test (Java+testng+ant+jenkins) sixth article TestNG II

Source: Internet
Author: User
Tags testng

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.