How to run test methods in specific order in JUnit4?

后端 未结 18 1841
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 04:35

I want to execute test methods which are annotated by @Test in specific order.

For example:

public class MyTest {
    @Test public void          


        
18条回答
  •  孤街浪徒
    2020-11-22 05:11

    What you want is perfectly reasonable when test cases are being run as a suite.

    Unfortunately no time to give a complete solution right now, but have a look at class:

    org.junit.runners.Suite
    

    Which allows you to call test cases (from any test class) in a specific order.

    These might be used to create functional, integration or system tests.

    This leaves your unit tests as they are without specific order (as recommended), whether you run them like that or not, and then re-use the tests as part of a bigger picture.

    We re-use/inherit the same code for unit, integration and system tests, sometimes data driven, sometimes commit driven, and sometimes run as a suite.

提交回复
热议问题