jQuery in Action, 3rd edition
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.

CreateObjects.java(10 testcases)
UpdateObjects.java(10 testcases)
GetObjectst.java(10 testcases)
DeleteObjects.java(10 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: http://aspose.com/file-tools
    subject: Junit Execution order
    jQuery in Action, 3rd edition