@FixMethodOrder(MethodSorters.NAME_ASCENDING) 在 Junit4 和 5 组合代码中不起作用

@FixMethodOrder(MethodSorters.NAME_ASCENDING) is not working in Junit4 and 5 combined code

这是代码:

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class TCSix {

    @BeforeAll
    static void setUpBeforeClass() throws Exception {
    }

    @AfterAll
    static void tearDownAfterClass() throws Exception {
    }

    @Test
    void aTestBlankEmailValidation() {
        fail("Not yet implemented");
    }

    @Test
    void bTestRegistrationORLogin() {
        fail("Not yet implemented");
    }


    }

这里 bTestRegistrationORLogin() 将首先 运行 代替 aTestBlankEmailValidation(),正如我声明的那样 FixMethodOrder 在上面。

It is recommended that test methods be written so that they are independent of the order that they are executed

但是,对于您的情况,请确保两件事:

  1. JUnit 版本高于 4.11
  2. JUnit 不是 5,因为那里的注解还不受支持