aspose file tools*
The moose likes Other Open Source Projects and the fly likes Controlling JUnit test method execution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Controlling JUnit test method execution" Watch "Controlling JUnit test method execution" New topic
Author

Controlling JUnit test method execution

Jay Damon
Ranch Hand

Joined: Jul 31, 2001
Posts: 282
I have created a JUnit test class in which I would like the various "test" methods to be run in a specific order. I have found that the test methods execute in different sequences depending upon the JVM that the JUnit test class is run in.
Looking at the API, I thought that overriding runTest() was the answer but this apparently executes once for each "test" method in the JUnit test class (and there are 8 in my test class). So, it executes the test methods in the proper order but it does so 8 times in my JUnit test class!
My immediate solution is to use a static count variable, check and increment it during runTest() execution. The other possible solution would be to rename all the "test" methods on the JUnit test class. However, it seems there should be an easier way.
I would appreciate any suggestions.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Why do you want the tests to run in a specific order? I hope you don't have any state dependencies between test methods...


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Controlling JUnit test method execution