How to run test methods in specific order in JUnit4?

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

    With JUnit 5.4, you can specify the order :

    @Test
    @Order(2)
    public void sendEmailTestGmail() throws MessagingException {
    

    you just need to annotate your class

    @TestMethodOrder(OrderAnnotation.class)
    

    https://junit.org/junit5/docs/current/user-guide/#writing-tests-test-execution-order

    i'm using this in my project and it works very well !

提交回复
热议问题