The Artima Developer Community
Sponsored Link

Oh Boy! Another Testing Tool!
Building Conformance and Unit Tests with Artima Testkit
by Bill Venners

<<  Page 6 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. A sub-Suite is merely a Suite that is held onto 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 ServiceUI CTK has a main Suite for the entire CTK that has no test methods, only sub-Suites. It's constructor instantiates the Suite objects that are needed by the CTK and adds them as sub-Suites to itself via the addSubSuite method. Here is this snippet of code from ServiceUITestKit's constructor:

    public ServiceUITestKit() throws IOException, ClassNotFoundException {

        System.setSecurityManager(new RMISecurityManager());

        APISuite apiSuite = null;

        // ...snipped out code that deserializes an APISuite
        // into the apiSuite variable...

        addSubSuite(apiSuite);

        addSubSuite(new AccessibleUISuite());
        addSubSuite(new LocalesSuite());
        addSubSuite(new RequiredPackagesSuite());
        addSubSuite(new UIFactoryTypesSuite());
        addSubSuite(new UIDescriptorSuite());
        addSubSuite(new UIDescriptorBeanSuite());
    }

Missing from the above code snippet is code that deserializes a com.artima.signaturetest.APISuite from a file. The APISuite object is itself the base Suite in a large tree of Suite objects that verify a candidate incarnation of the ServiceUI API has all the required, and no extra, packages, types, fields, and methods. The APISuite tree of objects was generated automatically by Artima SignatureTest, which inspected a golden incarnation of the ServiceUI API to determine what packages, types, fields, and methods were required. This tree of objects was then serialized to a file that is distributed as part of the ServiceUI CTK. For information on using Artima SignatureTest, see A SignatureTest Tutorial (coming soon to this website).

Figure 2 shows the structure of the ServiceUI CTK in memory. ServiceUITestKit is the base Suite in the tree. APISuite has both test methods and sub-Suites. APISuite's sub-Suites are not shown in the figure. The other Suites declare test methods but do not contain sub-Suites.



Figure 2. The ServiceUI CTK is a tree of Suite objects.

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

<<  Page 6 of 8  >>


Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use