This question already has an answer here:
-
How to change tests execution order in JUnit5?
2 answers
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
JUnit issue is still open https://github.com/junit-team/junit5/issues/13
So, right now there is no such possibility.
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
Unfortunately at the moment there is currently no mechanism in JUnit5 for ordering the execution of tests.
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.