简体   繁体   中英

Running test classes granularly in TestNG

I have my integration test suite running on TestNG and utilizing its annotations. In simplified case I have 3 test classes that contain 1 configuration test and some dependable on the configuration tests.

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() {}

My problem that when I run all those 3 test classes it runs it in the following order: TestClass1.configureTestMethod(), TestClass2.configureTestMethod(), TestClass3.configureTestMethod(), TestClass1.testCase1_1(), TestClass1.testCase1_2(), TestClass2.testCase2_1(), TestClass2.testCase2_2(), ...etc...

I know it makes sense cause there are no dependencies between configureTestMethod() in different classes so for TestNG their order doesn't meter.

How can I run all test methods of test classes before proceeding to another test class?

The directions I discovered so far:

  1. Define dependencies between configureTestMethod() in different test classes. It means I can't run a single test class cause it's dependent on another one.

  2. Implementing method interceptor. I'm getting there three configureTestMethod() methods and it doesn't matter for me in which order it's executed. I want to run their class methods first, so I'm sure how I can control it in the interceptor.

If you create testing.xml file, then at default all test classes mentioned in it will run in the order they are mentioned there. Just what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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