File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes Junit Execution order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Junit Execution order" Watch "Junit Execution order" New topic

Junit Execution order

Kowshik Nandagudi
Ranch Hand

Joined: Dec 09, 2010
Posts: 57
Hi All,

I have few classes where i have Junit testcase.

Ex: testcases) testcases) testcases) testcases);

When i execute the test cases in this class individually it executed properly in the order of occurence,

However when i put it in a test suite. The testcases are executed in a different order which has cascading effect and my test suite result is affected.

I am using junit 4.6 in eclipse environment.

Could anybody please help me out in sorting this .

Thanks in advance
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

I don't think there is anything in JUnit to tell a runner to order tests (I may be wrong, but there certainly never used to be). The usual pattern for testing is:
  • set up
  • run test
  • tear down

  • Which is why JUnit supplied the @Before and @After annotations. If you really need to control the ordering of test cases you'll need to define these in a test suite.

    JavaRanch FAQ HowToAskQuestionsOnJavaRanch
    I agree. Here's the link:
    subject: Junit Execution order
    It's not a secret anymore!