Does JUnit 5 support test method execution in alphabetical order or any similar functionality? [duplicate]

一个人想着一个人 提交于 2020-01-02 18:39:23

问题


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

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