2015-12-21 60 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(); 
} 
} 
相关问题