'Does JUnit 5 support test method execution in alphabetical order or any similar functionality? [duplicate]
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
Solution 1:[1]
JUnit issue is still open https://github.com/junit-team/junit5/issues/13 So, right now there is no such possibility.
Solution 2:[2]
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.MethodName.class)
public class TestClass{
//..
}
This Annotation is sorting by the actual method name, not the Displayname.
Solution 3:[3]
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
}
}
Solution 4:[4]
Unfortunately at the moment there is currently no mechanism in JUnit5 for ordering the execution of tests.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Yaroslav |
Solution 2 | Ruslan Bes |
Solution 3 | Edward D. Wilson |
Solution 4 | zappee |