About Us
Home
Contributors
License
Components
Sandbox
Jelly
Overview
FAQ
Getting Started
Tutorial
Detail
JellyDoc
Download
Tag Reference
Community
IRC
Powered By
To Do List
Features
JellyUnit
JellySwing
JellySWT
XML Pipeline
Core Tags
Tag Libraries
General Information
Charter
Volunteering
Contributing Patches
Releasing Components
Jakarta Community
Get Involved
Mailing Lists
Commons Resources (Unofficial)
Wiki
Japanese Translation
Korean Translation
Related
DB Commons
XML Commons

### JellyUnit

JellyUnit is a Jelly based JUnit testing mechanism. This allows Jelly scripts to be used to perform unit testing which can be particularly useful if you wish to test XML, XPath, SQL, HTTP, JMS or SOAP interactions.

JellyUnit works by using the JUnit library in a Jelly script to create JUnit TestSuite and TestCase objects. There are all the usual JUnit assertion tests available such as <assert> <assertEquals> and <fail>. You can use both Jexl and XPath expressions in the <assert> tag via either the test or the xpath attributes.

Inside these test scripts you can use the full range of Jelly tags such as navigating over XML test data creating multiple test cases based on sample data, performing SQL operations, SOAP calls, HTTP or JMS requests etc.

You can also use Ant FileSets and the <fileScanner> tag to iterate over collections of Jelly scripts or XML data files and use this data to define new test cases.

### Examples

There is a simple example JellyUnit script here

An example demonstrating the use of the Betwixt library is here along with a common shared test script here

The validate library can be used to perform XML validation inside JellyUnit. For example there's an example JellyUnit script validating XML here

### Mock Tags

In unit testing scenarios its often useful to use Mock Objects to test application logic and stub the behaviour of other service

JellyUnit supports a feature called Mock Tags which are very similar to Mock Objects. Mock Tags were invented by by Joe Walnes.

Essentially the technique is to mock, or stub the behaviour of Jelly tags so that they give the results that you expect from services. For example imagine you had a Jelly script with tags which worked with databases or web services. You could use mock tags to stub what the tags are meant to do, to test your script invokes them correctly without requiring the underlying services

There's an and example of using Mock Tags via the define library here which creates the mock tags, inside a JellyUnit test case and then invokes this example service using the mock tags rather than the underlying SQL and web service tags. Running the same service from outside of the Mock Tags JellyUnit test case would use the real tag implementations.

### Integration with TestRunners

To integrate cleanly inside JUnit TestRunner frameworks there is a helper class, JellyTestSuite which you can derive from to produce a single Java class which has a static suite() method to create a TestSuite object containing all the test cases created by the JellyUnit files. There is an example of this in action.

So if you had a test suite defined in a jelly script suite.jelly in a package com.acme.foo then you could create a class, capable of being ran inside any JUnit test runner framework as follows

    package com.acme.foo;

    import junit.framework.TestSuite;

    import org.apache.commons.jelly.tags.junit.JellyTestSuite;

    /**
     * A helper class to run jelly test cases in a JUnit TestRunner
     */
    public class TestFoo extends JellyTestSuite {

        public static TestSuite suite() throws Exception {
            return createTestSuite(TestFoo.class, "suite.jelly");
        }
    }