2015-12-21 19 views
1

我開始在TestNG中使用selenium webdriver。我創建了一個可以運行多個測試的多重測試類,但是,如何在每個測試塊中調用其他類而不復制整個代碼?TestNG - 如何調用MultipleTest類中的單個測試類

public WebDriver driver; 
    //Test 1 
    @Test(priority = 0) //Set Priority of Test - Priority of test always starts from Zero 
public void one() { 

    System.out.println("This is Test Case 1"); 
    } 
//Test 2 
@Test(priority = 1) // Test priority 1 
public void Two(){ 

    System.out.println("This is Test Case 2"); 
    } 

我需要創建一個函數來調用每個測試塊來運行其他類嗎?

回答

1

使用描述爲heresetUp()方法實例化該類並將其保留爲屬性。

在構建測試類 並運行任何測試方法之前,將調用setUp()方法。

import org.testng.annotations.*; 

public class MyTest { 

private MyService myService; 

@BeforeClass 
public void setUp() { 
     myService = new MyService(); 
} 

@Test 
public void testSomething() { 
     myService.doSomething(); 
} 
} 
相關問題