2

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.

Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44
Sejal Vala
  • 23
  • 1
  • 4

1 Answers1

2

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
BigGinDaHouse
  • 1,282
  • 9
  • 19
  • I am using both JUnit4 and 5 combined. – Sejal Vala Feb 15 '18 at 06:19
  • in JUnit 4 I have @FixMethodOrder(MethodSorters.NAME_ASCENDING) and it is working just fine, without any problems. To be sure the annotation cames from it check if it is and then if it is not correct but still not working , give respond here please – BigGinDaHouse Feb 15 '18 at 09:58
  • If I will use only JUnit 4 then it will work proper as per you said. But If I will mix both 4 and 5 it will not work. So I can go for JUnit 4 only for now. Thanks. – Sejal Vala Feb 19 '18 at 11:29
  • JUnit 5 have lots of differences in comparing with JUnit 4 , so I would suggest you to read a bit more about JUnit 5 before switching to it, cause it requires more changes than just including dependency – BigGinDaHouse Feb 19 '18 at 11:58