简体   繁体   English

在 Junit 4 中,用于创建测试执行的自定义顺序的 MethodOrderer 等价物是什么?

[英]What would be the equivalent of MethodOrderer in Junit 4 for creating custom order for test execution?

If I am not mistaken, Junit 5 allows creation of custom method orderers so that the order in which test methods are executed can be custom but I could not find something equivalent to this in Junit 4, there seems to be ways to order tests in alphabetical order or using JVM ordering etc. but nothing that allows for custom execution.如果我没记错的话,Junit 5 允许创建自定义方法排序器,以便可以自定义执行测试方法的顺序,但我在 Junit 4 中找不到与此等效的东西,似乎有按字母顺序排列测试的方法order 或使用 JVM ordering 等,但不允许自定义执行。 Is this something possible?这有可能吗?

note: I am aware of the fact that fixing test order is a bad practice however I am looking into this for research, not software development.注意:我知道修复测试顺序是一种不好的做法,但是我正在研究这个事实,而不是软件开发。

Starting JUnit 4.11, we have the annotation @FixMethodOrder and MethodSorters.class supporting the facility of setting an order for a test's execution.从 JUnit 4.11 开始,我们有注释@FixMethodOrderMethodSorters.class支持设置测试执行顺序的功能。

The package org.junit.runners.* needs to be imported to include the class MethodSorters .需要导入包org.junit.runners.*以包含类MethodSorters This class decides how the test cases need to be ordered.这个类决定了测试用例需要如何排序。 MethodSorters have three enum values. MethodSorters具有三个枚举值。

MethodSorters.DEFAULT
MethodSorters.JVM
MethodSorters.NAME_ASCENDING

Please take a look at JUnit Test Execution Order: Order Of Tests JUnit 4 Vs JUnit 5 for details.请查看JUnit 测试执行顺序:测试顺序 JUnit 4 Vs JUnit 5了解详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM