【问题标题】:TestNG - How to call individual Test classes in MultipleTest ClassTestNG - 如何在 MultipleTest 类中调用单个测试类
【发布时间】:2015-12-21 15:24:44
【问题描述】:

我开始在 TestNG 中使用 selenium webdriver。我创建了一个可以运行多个测试的多测试类,但是,如何在不复制整个代码的情况下调用每个测试块中的其他类?

 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");
  }

我是否需要创建一个函数来在每个测试块中调用以运行其他类?

【问题讨论】:

    标签: java selenium testing


    【解决方案1】:

    使用here 所述的setUp() 方法来实例化该类并将其保留为属性。

    setUp() 方法将在测试类构建完成后调用 在任何测试方法运行之前。

    import org.testng.annotations.*;
    
    public class MyTest {
    
     private MyService myService;
    
     @BeforeClass
     public void setUp() {
          myService = new MyService();
     }
    
     @Test
     public void testSomething() {
          myService.doSomething();
     }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多