How to run test methods in specific order in JUnit4?

后端 未结 18 2121
伪装坚强ぢ
伪装坚强ぢ 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:13

    I've read a few answers and agree its not best practice, but the easiest way to order your tests - and the way that JUnit runs tests by default is by alphabetic name ascending.

    So just name your tests in the alphabetic order that you want. Also note the test name must begin with the word test. Just watch out for numbers

    test12 will run before test2

    so:

    testA_MyFirstTest testC_ThirdTest testB_ATestThatRunsSecond

提交回复
热议问题