|
From: Darren D. <da...@da...> - 2004-07-22 08:02:01
|
> Rod Johnson wrote (in another thread): >> Alef, Darren >> >> Do either of you have time to experiment with the Groovy option? >> >> I think this is a very good idea. I've created some test cases in the main test tree (duplicates of one or two of the java based ones just for comparison). build.xml has been modified to compile the *.groovy files into the same target location (test-classes) too. The groovy compiler creates native bytecode so generated class files are interchangeable with java class files and the two languages can easily be mixed. For now, the groovyc task runs after the javac task in the buildtests target, so any classes that are duplicated (ie a FooBarTest.java and a FooBarTest.groovy file in the same package) will simply cause the resultant class file generated by javac to be overwritten by the one generated by groovyc. Obviously this won't be normal - tests will be written in one or the other - but applies where I've created a couple of duplicates for source comparison. JUnit simply sees the compiled classes as it would ones created with Java. <disclaimer> I'm a groovy noob - my source files will certainly be improvable! </disclaimer> IDE integration is another matter. Individual tests can be run by settin= g up a java application run target in Eclipse using a groovy supplied wrapper class that executes the tests but this is only useful for developing the tests. The JUnit integration reads the source directories not the binary target directory to get a list of classes to run, so it ignores *.groovy files in the test tree. There may be a way to make the JUnit integration read the output dir that I'm not aware of in which case it would work after compilation. Obviously there's the headache of not getting all the nice syntax highlighting, code completion, auto-compilation warnings etc. (you forget just how much Eclipse does for you!) There is a groovy Eclipse plugin, but I couldn't get it working with 3.0 final. The groovy devs on their IRC channel assured me a new one was imminent so this IDE support should improve soon. I don't know what integration is like for other IDE's. None of this is committed yet - I'll do it tonight and try to knock up a page in confluence about it. Unfortunately the groovy web site (groovy.codehaus.org) seems to be in a bit of a mess - broken Maven build or something? There's at least 2 versions of some of the pages (3 if you count what looks like an attempt to migrate it all to confluence) so it's tricky to navigate to or find the useful info. Of course, it's still pretty new stuff :) The language looks ideal for scripting unit tests - it has JUnit support built in. Favourite construct so far; void testFoo() { shouldFail( {bar.methodThatShouldThrowException()} ) } which replaces; void testFoo() { try { bar.methodThatShouldThrowException(); fail(); } catch (Exception e) { // expected } } Groovy! (sorry.) Collection handling, iteration, bean property setting and closures all look like serious verbosity savers in unit tests. Some things are no easier or less verbose than the java equivalents (at least with my very limited experience). D. --=20 Darren Davison Public Key: http://www.davison.uk.net/pages/key.htm |