繁体   English   中英

在TestNG中精细地运行测试类

[英]Running test classes granularly in TestNG

我的集成测试套件在TestNG上运行并利用其注释。 在简化的情况下,我有3个测试类,其中包含1个配置测试,并且其中一些依赖于配置测试。

TestClass1
  @Test()
  configureTestMethod() {}

  @Test(dependsOnMethods=["configureTestMethod"])
  testCase1_1() {}

  @Test(dependsOnMethods=["configureTestMethod"])
  testCase1_2() {}

TestClass2
  @Test()
  configureTestMethod() {}

  @Test(dependsOnMethods=["configureTestMethod"])
  testCase2_1() {}

  @Test(dependsOnMethods=["configureTestMethod"])
  testCase2_2() {}

TestClass3
  @Test()
  configureTestMethod() {}

  @Test(dependsOnMethods=["configureTestMethod"])
  testCase3_1() {}

  @Test(dependsOnMethods=["configureTestMethod"])
  testCase3_2() {}

我的问题是,当我运行所有这3个测试类时,它将按以下顺序运行:TestClass1.configureTestMethod(),TestClass2.configureTestMethod(),TestClass3.configureTestMethod(),TestClass1.testCase1_1(),TestClass1.testCase1_2(),TestClass2 .testCase2_1(),TestClass2.testCase2_2(),...等等...

我知道这是有道理的,因为在不同类中的configureTestMethod()之间没有依赖关系,因此对于TestNG,它们的顺序不正确。

在继续另一个测试类之前,如何运行测试类的所有测试方法?

我到目前为止发现的方向:

  1. 在不同的测试类中定义configureTestMethod()之间的依赖关系。 这意味着我不能运行单个测试类,因为它依赖于另一个测试类。

  2. 实现方法拦截器。 我到达那里三个configureTestMethod()方法,这对我来说执行顺序无关紧要。 我想先运行他们的类方法,所以我确定如何在拦截器中控制它。

如果创建testing.xml文件,则默认情况下,其中提到的所有测试类将按照在其中提到的顺序运行。 就是您想要的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM