• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Controlling JUnit test method execution

 
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want the tests to run in a specific order? I hope you don't have any state dependencies between test methods...
 
Beware the other head of science - it bites! Nibble on this message:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!