我开始将 selenium webdriver 与 TestNG 结合使用。我已经创建了一个可以运行多个测试的多测试类,但是,如何在不复制整个代码的情况下调用每个测试 block 中的其他类?
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");
}
我是否需要创建一个函数来调用每个测试 block 来运行其他类?
最佳答案
按照说明使用setUp()
方法here实例化该类并将其保留为属性。
The method setUp() will be invoked after the test class has been built and before any test method is run.
import org.testng.annotations.*;
public class MyTest {
private MyService myService;
@BeforeClass
public void setUp() {
myService = new MyService();
}
@Test
public void testSomething() {
myService.doSomething();
}
}
关于java - TestNG - 如何在 MultipleTest 类中调用单个测试类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34399072/