From: "Peter Lynch" <[EMAIL PROTECTED]> > Hi, > > Occasionally I discover scenarios where my jelly scripts appear broken. > > I want to write some jelly script test cases and commit then to jelly cvs but I > am not sure where I put those cases ( ie. which files ) and how/when they get > run. Most of my problems revolve around using Ant tasks in Maven jelly scripts. > > Could someone point me in the right direction?
Probably the trickiest part is testing that an Ant task really did what you think it did. I guess it depends on the Ant task as to how easy that'll be. The way unit testing of Jelly scripts and libraries works is typically using JellyUnit. You can always just use straight Java code if you like but typically for testing the behaviour of tags, expressions and libraries its often easier to just use them inside a Jelly script. There's some rudimentary documentation here... http://jakarta.apache.org/commons/sandbox/jelly/jellyunit.html Its usually easier to learn this kinda stuff via an example. Lets take a look here... http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/jelly/src/test/org/apa che/commons/jelly/dynabean/ this directory contains a JellyUnit test suite for the DynaBean library for Jelly. Most of the work goes into writing a JellyUnit script. Up to now we've been using the naming convention of suite.jelly but it can be called anything you like. If your test cases are very large, by all means refactor this file into lots of scripts. Either include them at specific points in the suite.jelly or use Ant FileSets and iterate over the sub-scripts etc. Looking at the suite.jelly should seem pretty self explanatory I hope; it defines a <test:suite> containing one or more <test:case>s which mirrors normal JUnit. Inside a <test:case> you can use various assertions and such like <test:assert> for performing boolean assertions using Jexl or XPath expressions and <test:assertEquals> for performing comparisons. http://jakarta.apache.org/commons/sandbox/jelly/tags.html#jelly:junit You can also perform XML validations of the output of a piece of Jelly script against a certain schema (DTD, XML Schema, RelaxNG, Relax, Trex) using the validate library and the <validate:assertValid> tag in particular... http://jakarta.apache.org/commons/sandbox/jelly/tags.html#jelly:validate When the script runs it actually creates a real JUnit TestSuite and TestCase(s) which can be ran as part of a regular JUnit test run. Typically all your unit test cases get run as part of the standard Ant/Maven build. One day hopefully, JellyUnit scripts could be integrated into Ant/Maven so that they get created and ran as part of the normal unit test run. However thats not there right now, so there's a simple adapter class which allows JellyUnit to be included in a standard Ant/Maven JUnit test run. If you look at the TestJelly.java class in the dynabean test directory... http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/jelly/src/test/org/apa che/commons/jelly/dynabean/TestJelly.java?rev=HEAD you'll see the adapter. This serves 2 purposes; it provides a main() that can be ran from the command line to create and run the JellyUnit test case. Also it creates a TestSuite class which has a static suite() method that any JUnit TestRunner can use to create and invoke the JellyUnit test cases. To check that the above is true, from inside the Jelly CVS checkout directory, you can type maven test:ui and you'll get a standard JUnit Swing test runner (which works like this for any Maven project) which can invoke any of the JellyUnit test cases inside the Jelly project. I hope all that helps... James ------- http://radio.weblogs.com/0112098/ __________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com -- To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>
