The Artima Developer Community
Sponsored Link

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

<<  Page 3 of 8  >>

Advertisement

Creating a Suite

To create a test suite, you simply subclass Suite and define test methods. For example, for the ServiceUI CTK I created class LocalesSuite and gave it eight test methods. As shown in Figure 1, LocalesSuite is a subclass of Suite. Its eight test methods include testConstructor, testEquals, and testSerializedForm.



Figure 1. LocalesSuite extends Suite and Defines Test Methods

You can partition testing responsibilities among Suite classes and test methods however you like. In the ServiceUI CTK, I tended to create one Suite class per ServiceUI class being tested. For example, LocalesSuite is responsible for testing one class in the ServiceUI API, net.jini.lookup.ui.attribute.Locales. Within a Suite, I tended to create one test method per ServiceUI method being tested. For example, the public interface of Locales looks like this:

package net.jini.lookup.ui.attribute;

import java.util.Locale;
import java.util.Iterator;
import java.util.Set;
import java.util.List;

public class Locales implements java.io.Serializable {

    public Locales(Set locales) {...}
    public boolean equals(Object o) {...}
    public int hashCode() {...}
    public Set getLocales() {...}
    public boolean isLocaleSupported(Locale locale) {...}
    public Iterator iterator() {...}
    public Locale getFirstSupportedLocale(Locale[] locales) {...}
    public Locale getFirstSupportedLocale(List locales) {...}
}
Table 3 shows the responsibilities of LocalesSuite's test methods:

Table 3. Responsibilities of LocalesSuite's Test Methods

Test Method Responsibility
public void testConstructor() Tests the Locales(Set locales) constructor
public void testEquals() Tests the equals(Object o) method
public void testHashCode() Tests the hashCode() method
public void testGetLocales() Tests the getLocales() method
public void testIsLocaleSupported() Tests the isLocaleSupported(Locale locale) method
public void testIterator() Tests the iterator() method
public void testGetFirstSupportedLocale() Tests the getFirstSupportedLocale(List locales) and getFirstSupportedLocale(Locale[] locales) methods
public void testSerializedForm() Tests the serialized form of Locales

If your are familiar with JUnit, you can think of class Suite as the JUnit types TestCase, TestSuite, Assert, and Test all collapsed into one type. Whereas JUnit uses the composite pattern to combine test cases into test suites, Testkit uses plain old composition. Any Testkit Suite can hold references to other Suites.

<<  Page 3 of 8  >>


Sponsored Links



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