Monday, 12 September 2016

Junit Test Suits and Test Execution Order

When you have large number test classes and you want to combine then and manage them the you can create a Test Suit. Execution of test case means execution of all test classes inside the Suite as per specified order.

The following example gives outline of Suit class. It contains 3 test classes FirstTestClass and SecondTestClass. You can add as many test classes as you want.

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

                ThirdTestClass.class })

public class AllTests {


Test Execution Order within Class - Junit Assumes that the test cases written inside class and independent and can be executed randomly.  But in case if you have to define the flow of Junit test cases within a class then there is annotations @FixMethodOrder which you can use. Consider below example with Class MyTests with Test Cases BTest(), ATest() and CTest() and we can define the order of execution as per method name ascending order alphabetically.

In following example the order of execution will be  -
1. ATest()
2. BTest()
3. CTest()

public class MyTests {

public void BTest()

public void ATest()

public void CTest()



  1. Thanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
    mobile application development training online
    mobile app development course
    mobile application development course
    learn mobile application development
    mobile app development training
    app development training
    mobile application development training
    mobile app development course online
    online mobile application development

  2. I was very pleased to find this site. I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

    Data Science Course

  3. Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
    Data Science Training Institute in Bangalore

  4. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
    Best Data Science Courses in Bangalore

  5. Two full thumbs up for this magnificant article of yours. I've really enjoyed reading this article today and I think this might be one of the best article that I've read yet. Please, keep this work going on in the same quality.

    Data Science Training

  6. Highly appreciable regarding the uniqueness of the content. This perhaps makes the readers feels excited to get stick to the subject. Certainly, the learners would thank the blogger to come up with the innovative content which keeps the readers to be up to date to stand by the competition. Once again nice blog keep it up and keep sharing the content as always.

    360DigiTMG Business Analytics Course