How to run junit tests in order as they present in your source code

By: Slav Kurochkin

To be able run your Junit test in specific order you can use following code, before your public class test {. Sorts the test methods by method name, in lexicographic order. So basically to be able get specific order you need to name your test like that: a_test (will be first), b_test(will be second), c_test(will be third)

@FixMethodOrder(MethodSorters.NAME_ASCENDING)

public class login {
@Test
public void a_test (will be first) {
   }
@Test
public void b_test(will be second) {
   }
}

You can find more information here

View Comments

Leave a Comment

Use markdown or basic HTML and be nice.