How to make sure TestNG runs methods on test classes in succession instead of interleaved?

后端 未结 7 2451
南笙
南笙 2020-12-14 03:41

The situation and the problem

I have several test classes, each with several test methods. All tests use the same test database in the background. Each test class

7条回答
  •  心在旅途
    2020-12-14 04:08

    Even in sequential mode TestNG could interleave test methods from the same suite. It does guarantee the sequence @BeforeClass -> @Test -> @AfterClass but it can do something like:

    before class1
        test class1.method1
    before class2
        test class2.method1
        test class1.method2
    after class1
        test class2.method2
    after class2
    

    The solution is to force each class in a different suite (which are executed truly sequentially). As of version 2.16, the maven surefire plugin puts each class in a separate suite so the problem is fixed.

    On the other hand, IDEA (even the latest 13 EAP) generates an xml file with all classes in the same suite. Hopefully IDEA will follow suit and fix this too. Interleaved tests are a showstopper when working with shared resources such as databases.

提交回复
热议问题