How to change tests execution order in JUnit5?

大兔子大兔子 提交于 2019-11-27 07:34:54

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/40665216/how-to-change-tests-execution-order-in-junit5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!