5 Jul 2004 11:42
Re: Running unit tests with the groovy command-line tool
On 5 Jul 2004, at 10:23, Laforge Guillaume wrote: >> Maybe we should change it that if the class does not have a static >> main >> method then it will try running it with TestRunner? > > So we should try first to run the main method if present ? Then only > run the test if it's a test ? > >> Incidentally, another tweak I'd like is, if a class is not a test case >> or have a main method but implements Runnable, then try instantiating >> the class (using a zero argument constructor, or one that takes a >> String[] args parameter), then call run(). > > That should be doable Mr Strachan> I'll try to see if I can do that this evening when I'm back home. > > So, to recap (in pseudo code): > > if (theClass has a main method) { > run the main method > } else if (theClass instanceof GroovyTestCase) { > use the test runner to run it > } else if (theClass implements Runnable) { > if (theClass has a constructor with String[] params) > instantiate theClass with this constructor and run > else if (theClass has a no-args constructor) > instantiate theClass with the no-args constructor and run > } > > Is it the desired behaviour ? Sounds great :) One minor nitpick, we might want to do the 2nd test case (does it extend GroovyTestCase) using reflection or something to avoid a ClassNotFoundException if folks are using the GroovyShell embedded inside some environment where junit is not on the classpath. No biggie though. James ------- http://radio.weblogs.com/0112098/
> I'll try to see if I can do that this evening when I'm back home.
>
> So, to recap (in pseudo code):
>
> if (theClass has a main method) {
> run the main method
> } else if (theClass instanceof GroovyTestCase) {
> use the test runner to run it
> } else if (theClass implements Runnable) {
> if (theClass has a constructor with String[] params)
> instantiate theClass with this constructor and run
> else if (theClass has a no-args constructor)
> instantiate theClass with the no-args constructor and run
> }
>
> Is it the desired behaviour ?
Sounds great :)
One minor nitpick, we might want to do the 2nd test case (does it
extend GroovyTestCase) using reflection or something to avoid a
ClassNotFoundException if folks are using the GroovyShell embedded
inside some environment where junit is not on the classpath. No biggie
though.
James
-------
RSS Feed