jastrachan | 15 May 08:16 2004
Picon

Re: [groovy-dev] Implicit main() method for test classes

On 13 May 2004, at 23:28, Alexey Verkhovsky wrote:
> Context: all methods for running a single test case that are listed in
> http://groovy.codehaus.org/Unit+Testing are either too slow (anything 
> to
> do with Maven), or fairly difficult to set up (launching JVM with four
> or five jars on -classpath).
>
> In Ruby, if I have a MyTest.rb file, and it contains unit tests,
> 'ruby MyTest.rb' does the obvious thing - executes all tests in that
> file.
>
> Is there a way to know which .groovy file is executed? If
> GroovyTestCase.main() could get an answer to this question, it would be
> possible to implement the same behavior.

I've really wanted this feature for some time too. When we first 
started writing groovy tests cases I thought to implement this properly 
we would need macros or mixins.  Basically static methods stay in the 
class in which they are defined. So if I write MyTestCase there's no 
magic main method created which knows how to run the MyTestCase. So 
adding a static main() to GroovyTestCase wouldn't know which script was 
actually just run etc.

This is a common smell I've felt with Java code; if I overload a class 
with a main() method, we must also write another main method.

Maybe a simple solution to this would be an alternative to the static 
main() method mechanism. This came up on the list before

http://lists.codehaus.org/pipermail/groovy-dev/2004q1/000868.html

So maybe we could auto-generate a static main() in the bytecode if an 
object has a matching constructor that can take a String[] args 
parameter and implements the Runnable interface? Then we could 
implement all this in the base GroovyTestCase and then allow an 
individual test case to be ran via any Java tool (since any test case 
will have a main() method auto-generated for it if the developer 
doesn't write one).

James
-------
http://radio.weblogs.com/0112098/

Gmane