[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.
