Parametric testing of testng, shared thread pool configuration, parameter default configuration

Source: Internet
Author: User
Tags testng

When testing with testng, there are often parameterized configurations, such as database, connection pool, thread pool number,

Automated reading with testng parameters @parameter annotations


Run the test code configuration in a multithreaded manner: Configure Data-provider-thread-count= "20" in the ' <suite> ' tab

Java code:

/** * * <p> * title:testngparameters * </p> * * <p> * Reference profile Testng-parameters.xml * Description: Parametric test Configure the executable parameters in the configuration file, using the @parameters annotations to invoke, the parameter names and types in the annotations must be consistent with the configuration file * Multithreaded Test: Configure data-provider-thread-count= in the ' <suite> ' tab * </p> * * <p> * Company: * </p> * * @author: Dragon * * @date: October 13, 2014 */public class Tes tngparameters {//@Parameters the corresponding parameter name in the annotation and the key in the configuration file must be the same @parameters ({"First-name"}) @Testpublic void testsinglestring (String secondname) {System.err.println ("invoked teststring" + secondname); assert "Cedric". Equals (Secondname);} @Parameters ({"Count"}) @Testpublic void Testsingleinteger (Integer count) {System.err.println ("invoked count" + count); Assert count.intvalue () = = 8;} private string M_datasource;private string m_jdbcdriver;private int poolsize;/** * <p> * Description: NOTE: @ The parameter order of the parameters definition must be the same as the parameter order of the method, the parameter in the configuration file is only the same as the parameter name of the annotation * </p> * * @param ds * @param driver * @param poolsize */@Parame Ters ({"DataSource", "jdbcdriveR "," Poolsize "}) @BeforeMethodpublic void Beforetest (String ds, string driver, int poolsize) {This.m_datasource = Ds;this. M_jdbcdriver = Driver;this.poolsize = Poolsize; System.err.println (Getm_datasource () + "---" + getm_jdbcdriver () + "---" + getpoolsize ()); Public String Getm_datasource () {return m_datasource;} Public String Getm_jdbcdriver () {return m_jdbcdriver;} public int getpoolsize () {return poolsize;} /** * If parameter db is not specified in the configuration file, then the parameter value will use the default value ' mysql ' * @param db */@Parameters ("db") @Testpublic void Testnonexistentparameter (@ Optional ("MySQL") String db) {System.err.println ("DB:" + db);}}

configuration file: Testng-parameter.xml

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE Suite SYSTEM "Http://testng.org/testng-1.0.dtd" ><!--data-provider-thread-count= "20" Shared thread pool configuration <suite name= "framework_testng" data-provider-thread-count= "><parameter name=" First-name "value=" Cedric "/><parameter name=" Count "value=" 8 "/><parameter name=" datasource "value=" Com.dbcp.source "/>< Parameter Name= "Jdbcdriver" value= "Com.mysql.jdbc.driver"/><parameter name= "poolsize" value= "/><" Test verbose= "2" name= "testgroups" ><classes><class name= " Com.dragon.testng.annotation.TestngParameters "/></classes></test></suite>
Test Results:

Com.dbcp.source---com.mysql.jdbc.driver---10db..  Mysqlcom.dbcp.source---com.mysql.jdbc.driver---10Invoked count 8com.dbcp.source---com.mysql.jdbc.driver--- 10Invoked teststring cedricpassed:testnonexistentparameter ("MySQL") Passed:testsingleinteger (8) PASSED: Testsinglestring ("Cedric") ===============================================    testgroups    Tests Run:3, failures:0, skips:0===============================================



If I forgive,

Don't think I have no principles. Because I understand that
If you have to spare someone and forgive, you can't do anything.


Parametric testing of testng, shared thread pool configuration, parameter default configuration

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.