testNG的高級用法 --DataProvider


@DataProvider
Method參數
數據提供者的第一個參數是java.lang.reflect.Method,TestNG傳遞這個將調用的測試方法。如果您希望數據提供者根據不同的測試方法返回不同的數據,那么這種做法就非常有用。
 
package com.test.jwen.httpApiAuto;
 
import java.lang.reflect.Method;
 
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
 
public class TestNg2 {
 
 
    @DataProvider
    public Object[][] provideNumbers(Method method){
         String methodName = method.getName();
 
         if (methodName.equals("two")){
             return new Object[][]{new Object[] {2}};
         }
         if (methodName.equals("three")){
             return new Object[][]{new Object[] {3}};
         }
         return null;
 
    }
 
    @Test(dataProvider = "provideNumbers")
    public void two(int param){
         System.out.println("Two received : " + param);
    }
 
    @Test(dataProvider = "provideNumbers")
    public void three(int param){
         System.out.println("Three received : " + param);
    }
}

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM