Diasparsoft Logo Let's write software that people understand.

Home | Contact

Training

JUnit support

Outsourcing

The work that Diasparsoft did for us was outstanding. We are now using the software on a daily basis and their work could well have a dramatic impact on the Reds' organization in the near future.Cincinnati Reds Baseball Club.


Publications

Tips & Tricks

Diasparsoft Toolkit

What is Diaspar?

Interesting Bits RSS

Home » Archives » June 2004 » Recipe: Eclipse doesn't run my tests correctly

[Previous entry: "Sloppy writing"] [Next entry: "The same tests at all levels?"]

06/24/2004: "Recipe: Eclipse doesn't run my tests correctly"


Problem. You have a simple JUnit test case that can be run from a command line or batch file. You pass in one argument to the test case, the main() method picks this up. The test runs fine. When you run the exact same test in the Eclipse plugin, your main() method never gets invoked.

Background. I imagine that, to run the test case, you are right-clicking the class, then choosing Run As | JUnit Test. When you do this, the Eclipse test runner acts like the base JUnit test runners: it collects all the methods matching test*() and builds a suite from them.

Recipe. To have Eclipse invoke your main() method, right-click the class, then choose Run As | JUnit Application, rather than JUnit Test.

Discussion. Think about what the JUnit Swing UI test runner does when you press the Run button. It doesn't invoke main(), either. With this in mind, the Eclipse test runner's behavior makes perfect sense.