The Source for Java Technology Collaboration


How to write a custom test case

Overview

There are two kinds of test case used for Mobicents. The first is the set of JSLEE Test Compliance Kit (TCK). The TCK is a normative set of tests that accompanies JSR 22 and is used to ensure compliance of the Mobicents implementation with the JSLEE 1.0 standard. The second kind of test cases covers additional Mobicents functionality, not captured in the TCK. We will refer to the second kind as custom test cases.

Event though custom test cases are not directly related to the TCK and they do not need to be, we recommend use of the TCK framework offered by the TCK, which simplifies development of new tests.

Test case structure

A test case is comprised of the following key components:

  1. Test descriptor. This is an xml file, which gives the test a unique name, specifies the main test class and passes runtime properties to the test framework.
  2. Test client. The test client is executed outside of the SLEE and it interacts with it via specialized Resource Adaptor.
  3. Test SLEE deployment unit. This is a bundle of SLEE components specific to the test that is deployed in the SLEE before the test is executed and is undeployed after the test is finished.
  4. Test build file - custom-components.xml. This is an ant file invoked by the main test build script. It prepares for deployment the test specific artifacts.

Example test case

Let's look at an existing test case, which can be used as a guideline for new tests. All custom tests are located under the

tests/ directory
of the Mobicents project source tree. The test we are going to look at is named CMPTest. Its files are located under src/org/mobicents/sleetests/sbb/cmp/setSideEffects. Let's examine the test artifiacts.

Test descriptor - CMPTest.xml. Following is the annotated xml file:

<test-description>
 <!-- Set the test name -->
 <title>CMPTest</title>
 
 <!-- Specify the main test class that will drive the test. It will run outside of the SLEE and 
  will interact with the DU given below via specialized RA over an unique activity name -->
 <executeClass>org.mobicents.sleetests.sbb.cmp.setSideEffects.CMPTest</executeClass>
 
 <!-- The Deployment Unit specific for this test. It will be deployed in the SLEE before the test client is run and undeployed after it ends. -->
 <property name="serviceDUPath" value="org.mobicents.sleetests.sbb.cmp.setSideEffects.CMPTest-du.jar"/>
 
 <!-- The unique SLEE activity name over which the test client and the associated DU will interact -->
 <property name="activityName" value="CMPTest"/>
 
</test-description>

The test client CMPTest.java extends AbstractSleeTCKTest?, which does most of the setup/tearDown work for the test and provides convenience utilities. We will not cover all the details of AbstractSleeTCKTest? here, but the reader is enouraged to fetch the source code from the SLEE TCK and examine it when time permits. The two key methods in CMPTest.java are setUp() and run(). The first one delegates the bulk of the setup work to the superclass and registers a callback listener TestResourceListenerImpl? for events fired by the server side test components. The specialized test Resource Adaptor ensures that events fired in the SLEE on the appropriate activity initiated by the RA are delivered to the test client. The run() method is where the client side logic of the test case takes place.

The Deployment Unit for this example consists of one JSLEE service and two SBBs. The java files for the SBBs are located in the source directory (same location as the test descriptor and client files). The SLEE descriptor files are located under META-INF/.

The build file is located in the same directory as the test descriptor and is self explanatory.

Building custom tests

To build the custom test suite, go to the tests/ directory and run

ant
.

Running custom tests

Before running custom tests make sure that the Mobicents server is running. One or more tests can be run via

ant run-tests
given a root package name. For example if the
run-tests
command is given a parameter "-Dtests=org" this will result in running all tests that have descriptors under the src/org directory. To run a subset of tests or a single test, the value of the tests parameter has to be a more specific package name or the full path to a test descriptor. Here is how to run CMPTest:


tests> ant run-tests -Dtests=org/mobicents/sleetests/sbb/cmp/setSideEffects/CMPTest.xml

To run all tests located in subdirectories of org/mobicents/sleetests/sbb/cmp


tests> ant run-tests -Dtests=org/mobicents/sleetests/sbb/cmp

Running ALL tests

To run all tests including the TCK testsuite as well as the custom testsuite, go to the mobicents source root directory and run


mobicents> ant all-tests

-- Main.ivelin - 16 Jun 2006

Topic MobicentsHowToWriteTestCase . { Edit | Ref-By | Printable | Diffs r2 < r1 | More }
 XML java.net RSS

Revision r2 - 20 Jun 2006 - 22:44:11 - Main.ivelin
Parents: WebHome > MobicentsOpenSLEE > MobicentsFAQ