久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

TestNG DataProvider的幾種方法寫法

 liuchangxin81 2014-05-27

前面寫過一個(gè)無參的數(shù)據(jù)提供者方法,,還有三種有參數(shù)據(jù)提供者方法。

一,、Method表示當(dāng)前測(cè)試的方法

Dataprovidertest.java代碼

package com.tzf.testng;
 
import java.lang.reflect.Method;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
 
public class DataProviderTest {
     
    @DataProvider
    public Object[][] providerMethod(Method method){
        Object[][] result = null;
        if(method.getName().equals("testmethod1")){
            result = new Object[][]{new Object[]{1}};
        }else if(method.getName().equals("testmethod2")){
            result = new Object[][]{new Object[]{2}};
        }else{
            result = new Object[][]{new Object[]{3}};
        }
        return result;
    }
     
    @Test(dataProvider="providerMethod")
    public void testmethod1(int param){
        System.out.println("method1 received:"+param);
    }
     
    @Test(dataProvider="providerMethod")
    public void testmethod2(int param){
        System.out.println("method2 received:"+param);
    }
     
    @Test(dataProvider="providerMethod")
    public void testmethod3(int param){
        System.out.println("method3 received:"+param);
    }
}

 注意這里我的Dataprovider的name值沒有指定,,默認(rèn)用的是方法名。 Testng.xml代碼

復(fù)制代碼
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
    <test name="DataProviderTest">
        <classes>
            <class name="com.tzf.testng.DataProviderTest" />
        </classes>
    </test>
</suite>
復(fù)制代碼

運(yùn)行結(jié)果代碼

RemoteTestNG starting
method1 received:1
method2 received:2
method3 received:3
RemoteTestNG finishing: 145 ms

二,、ITestContent當(dāng)前測(cè)試的上下文信息

Dataprovidertest2.java代碼

復(fù)制代碼
package com.tzf.testng;

import java.util.Random;

import org.testng.ITestContext;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class DataProviderTest2 {
    
    @DataProvider
    public Object[][] providerMethod(ITestContext context){
        String[] groups = context.getIncludedGroups();
        int size = 2;
        for(String group : groups){
            if(group.equals("function-test")){
                size = 10 ;
                break;
            }
        }
        Object[][] result = new Object[size][];
        Random r = new Random();
        for(int i=0;i<size;i++){
            result[i] = new Object[]{new Integer(r.nextInt())};
        }
        return result;
    }
    
    @Test(dataProvider="providerMethod",groups={"function-test","unit-test"})
    public void testmethod1(Integer n){
        System.out.println("method1 received:"+n);
    }
    
}
復(fù)制代碼

Testng.xml代碼

復(fù)制代碼
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
    <test name="DataProviderTest2">
        <groups>
            <run>
                <include name="function-test"/>
                <exclude name="unit-test"/>
            </run>
        </groups>
        <classes>
            <class name="com.tzf.testng.DataProviderTest2" group="function-test"/>
        </classes>
    </test>
</suite>
復(fù)制代碼

運(yùn)行結(jié)果代碼

復(fù)制代碼
RemoteTestNG starting
method1 received:-1987654923
method1 received:338477914
method1 received:1910366338
method1 received:107205369
method1 received:-1018164959
method1 received:-2060129321
method1 received:-803464435
method1 received:-814156781
method1 received:-1075504680
method1 received:-774924512
RemoteTestNG finishing: 151 ms

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多