0
votes

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.

1
What if remove the dependencies in annotation, and annotating configuration methods with @BeforeClass ?Amir Pashazadeh
Just tried that. It executes all the @BeforeClass methods for all classes at the beginning.Soid

1 Answers

0
votes

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.