问题
JUnit 4 has @FixMethodOrder(MethodSorters.NAME_ASCENDING)
to support test execution in alphabetical order.
Is there any similar functionality introduced in latest JUnit 5 or any other way to achieve this?
I went through some of the similar issue but could not find any solution. So posting this question again to check for a solution.
Thanks
回答1:
JUnit issue is still open https://github.com/junit-team/junit5/issues/13 So, right now there is no such possibility.
回答2:
Finally, this is now possible.
@TestMethodOrder is avaliable at snapshot version. (5.4)
@TestMethodOrder(OrderAnnotation.class)
class OrderedTestsDemo {
@Test
@Order(1)
void nullValues() {
// perform assertions against null values
}
@Test
@Order(2)
void emptyValues() {
// perform assertions against empty values
}
@Test
@Order(3)
void validValues() {
// perform assertions against valid values
}
}
source: doc and commit
回答3:
I know I'm late but JUnit5 is capable of that.
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.TestMethodOrder;
@TestMethodOrder(MethodOrderer.Alphanumeric.class)
public class TestClass{
//..
}
This Annotation is sorting by the actual method name, not the Displayname.
回答4:
Unfortunately at the moment there is currently no mechanism in JUnit5 for ordering the execution of tests.
来源:https://stackoverflow.com/questions/50063402/does-junit-5-support-test-method-execution-in-alphabetical-order-or-any-similar