The Artima Developer Community
Sponsored Link

Artima SuiteRunner Tutorial
Building Conformance and Unit Tests with Artima SuiteRunner
by Bill Venners
February 10, 2003

<<  Page 5 of 8  >>

Advertisement

Using Sub-Suites to Build a Tree of Suites

A Suite consists of zero to many test methods and zero to many sub-Suites. As mentioned previously, a sub-Suite is merely a Suite that is held in a composition relationship by another Suite. The referenced Suite is called a sub-Suite of the referencing Suite. The customary manner to create larger tests is to define focused Suite classes, then aggregate them together as sub-Suites of other Suite classes. An entire test suite is then represented in memory by a tree of Suite objects, starting at a base Suite whose execute method kicks off a run of the entire suite of tests.

The account example has a main Suite, called AccountTestKit, that has no test methods, only sub-Suites. Its constructor instantiates two Suite objects and adds them as sub-Suites to itself via the addSubSuite method. AccountTestKit represents the full conformance test kit for the com.artima.examples.account.ex6 package. Here is the entire AccountTestKit class:

package com.artima.examples.account.ex6test;

import org.suiterunner.Suite;

public class AccountTestKit extends Suite {

    public AccountTestKit() {

        addSubSuite(new AccountSuite());
        addSubSuite(new InsufficientFundsExceptionSuite());
    }
}

Figure 2 shows the structure of the AccountTestKit in memory. AccountTestKit, the base Suite in the tree, holds references to two sub-Suites. These two sub-Suites, AccountSuite and InsufficientFundsExceptionSuite, declare test methods but do not themselves contain sub-Suites.



Figure 2. The AccountTestKit is a tree of Suite objects.

When the Runner invokes execute on the AccountTestKit object, execute first invokes executeTestMethods on itself. executeTestMethods uses reflection to discover that AccountTestKit has no test methods, and returns. execute then invokes executeSubSuites, which invokes execute on each of its two sub-Suites. The execute methods of each of those Suites ensures that all test methods executed.

<<  Page 5 of 8  >>


Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us