How to change tests execution order in JUnit5?

前端 未结 2 1288
隐瞒了意图╮
隐瞒了意图╮ 2020-12-11 14:58

JUnit4 has @FixMethodOrder annotation which allows to use alphabetical order of test methods execution. Is there analogous JUnit5 mechanism?

相关标签:
2条回答
  • 2020-12-11 15:22

    Edit: JUnit 5.4 is officially released now, so no need to use snapshots anymore.

    This is now possible with JUnit 5.4.

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

    To control the order in which test methods are executed, annotate your test class or test interface with @TestMethodOrder and specify the desired MethodOrderer implementation. You can implement your own custom MethodOrderer or use one of the following built-in MethodOrderer implementations.

    Alphanumeric: sorts test methods alphanumerically based on their names and formal parameter lists.

    OrderAnnotation: sorts test methods numerically based on values specified via the @Order annotation.

    0 讨论(0)
  • 2020-12-11 15:28

    No, not yet. For unit tests, execution order should be irrelevant. For more complex tests, JUnit is aiming to provide explicit support - test ordering would be part of that.

    0 讨论(0)
提交回复
热议问题