2014-10-29 2 views
0

두 명의 데이터 제공 업체를 어떻게 결합하여 단일 업체로 만들 수 있습니까?testng에서 데이터 제공 업체를 결합하는 방법

@DataProvider 
public Object[][] Authentication() throws Exception{ 
     Object[][] testObjArray = ExcelUtils.getTableArray(System.getProperty("user.dir")+"/inputs/JoinnowTest.xlsx","Sheet1",4); 
     return (testObjArray); 
} 

@DataProvider 
public Object Browsername() throws Exception{ 
     Object browser = "Iexplore"; 
     return browser; 
} 

이 두 데이터 제공 업체를 결합하고 싶습니다.

답변

0

당신은 간단한 새로운 클래스를 생성하고 다음과 같이 함께 모두 (객체 [] []와 객체) 자료 구조를 넣을 수 있습니다이 :

public class DataProviderContainer { 

    private Object[][] auth; 
    private Object browser; 

    public DataProviderContainer(Object[][] auth, Object browser){ 
    this.auth= auth; 
    this.browser = browser; 
    } 
    public DataProviderContainer(Object[][] auth){ 
    this.auth= auth; 
    } 
    public DataProviderContainer(Object browser){ 
    this.browser = browser; 
    } 

    public Object[][] getAuth(){ 
    return this.auth; 
    } 

    public Object getBrowser(){ 
    return this.browser; 
    } 

    public void setAuth(Object[][] auth){ 
    this.auth= auth; 
    } 

    public void setBrowser(Object browser){ 
    this.browser = browser; 
    } 


} 

또한 예외가 포함 할 수 있습니다. ITestContext를 사용

0

// 당신은 예를 들어 하나의

@Test 공공 무효 TEST1() { 에서 System.out.println ("Test1을")를 muliple dataProviders에서는 결합 할 수 있습니다 개체;

} 

@Test 
public void test2() { 
    System.out.println("Test2"); 

} 

t.getName // 여기()가 실행하는 현재 테스트 케이스 이름을 반환

@DataProvider 
public Object[][] dataProvider(ITestContext t) throws Exception{ 
     Object[][] testObjArray = null; 
     if(t.getName().equals("test1")) 
     { 
      return <AUTHATICATE ARRAY> 
     } 
     else 
     { 
      return <BROWSER ARRAY> 
     } 
} 
관련 문제