This post originated from an RSS feed registered with Java Buzz
by Jon Tirsen.
Original Post: Why JUnit does not accept method as argument
Feed Title: jutopia
Feed URL: http://sedoparking.com/search/registrar.php?domain=®istrar=sedopark
Feed Description: Ramblings on Java, AOP, TDD, agile and so on. some like it jutopic!
I think this is based on one of the most common misunderstandings of what JUnit is. JUnit is a unit-testing tool not a functional testing tool. Feeling the urge to run an individual test-method and not the whole suite or test-case is actually a testing smell. There's a high chance you're actually writing functional tests and not unit-tests. A single JUnit test-case (consisting of several methods) should test one and only one unit of code (ie class or similar) and should take a very short amount of time to execute.
When you're in development mode (test-code-compile-cycle) it's better to use the JUnit-GUI to execute you're tests (it's capable of executing individual methods). Or you IDE, the latest IDEA-builds has an excellent JUnit runner (but it's always been quite good).
There are extensions to JUnit that does exactly this but those are for functional testing and not for unit-testing. (I think the most popular one is actually called JFunc but I can't remember. Never used it.)
Cedric's guess is that "if you are going to be testing more than small applications, you will start developing your own test software". It's actually quite the opposite. I was also annoyed with the limitations of JUnit when I used it for testing smaller libraries and application. When I actually used it to write a very large system I realized that those features I wanted (similar to what Cedric outline) were all actually quite useless.