Search code examples
javaseleniumjunitjunit4junit5

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


Here is the 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");
    }


    }

Here the bTestRegistrationORLogin() will run first in place of aTestBlankEmailValidation(), where as I declared FixMethodOrder on top.


Solution

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

    However, for your case, make sure two things:

    1. JUnit version is more than 4.11
    2. JUnit is not 5 , cause there the annotation is not supported yet