|
Recently Sun Microsystems released a set of tools called the Java Compatibility Test Tools (Java CTT). These tools are designed to help a specification lead, or other Java Community Process Program (JCP) member serving on an Expert Group, create a Technology Compatibility Kit (TCK). The JCP is an inclusive, consensus-building approach used by the international Java community to develop and evolve Java technology. If you are unfamiliar with the JCP, see the Java Community Process Program. This article gives you an overview of the Java CTT and generally describes how the tools can help JCP members create a TCK. It also focuses on one of the Java CTT tools, Spec Trac, and shows you how to use the tool. Future articles will show you how to use other Java CTT tools. What's a Technology Compatibility Kit?A Technology Compatibility Kit (TCK) is a suite of tests, tools, and documentation that provide a standard way of testing an implementation for compliance with a Java technology specification. It is one of the three major deliverables, along with a specification and reference implementation, that the JCP requires for the final release of a Java technology. The specification describes in detail a Java technology, for example, it describes the application programming interfaces (APIs) for the Java technology. The reference implementation (RI) is a working implementation of the Java technology to prove that the specification can be implemented. The TCK is used to test implementations for compliance with the specification. The specification is the responsibility of an Expert Group put in place for the Java technology. During the Proposed Final Draft stage of the process, an Expert designated as the specification lead (or simply, Spec Lead) is responsible for the completion of both the RI and the TCK. Each TCK is unique to its associated Java technology, however all TCKs must include the following:
In addition, a TCK can include the description of an audit process, which might, for instance, require independent verification by a third party of the test results. The Tools in the Java CTTThe Java CTT includes four tools:
This article shows you how to use Spec Trac. Future articles will show you how to use other Java CTT tools. Spec Trac -- A Tool for Tracking AssertionsAs mentioned earlier, the Java CTT provides a test harness -- the JavaTest harness. This directly addresses one requirement of a TCK. But there are other aspects of building a TCK that the Java CTT simplifies. This is especially true in building a TCK test suite for use with the JavaTest harness. One of the Java CTT tools that plays an important role in building a TCK test suite is the Spec Trac tool. In particular, a TCK test suite developer can use Spec Trac to: Using Spec Trac to Identify Assertions
TCK test suite developers need to analyze the documented specifications for an API to determine
what needs to be tested. To do this, test suite developers identify assertions, statements
that describe required characteristics of the API, in the specifications.
"Required" means that any implementation of the API must also implement those
characteristics.
For example, the following statement appears in the JCP specification
"J2ME Connected Device Configuration (JSR-36)".
It describes a
The statement is an example of an assertion. An implementation of the Connected Device Configuration
(CDC) profile must implement the Not all assertions are testable, for example, it's not always possible to test assertions about abnormal termination. In addition, not all assertions are explicitly stated in a specification -- some are implied. Those assertions that are testable (whether explicitly stated or implied) form the basis of a TCK test suite. In other words, all the testable assertions in a specification should be tested by the TCK test suite for the technology. The Spec Trac tool helps identify statements in a specification that are assertion candidates (it doesn't identify implied assertions). A TCK test suite developer needs to verify that the candidates are indeed assertions, and that they are testable. However because specifications can be large and complex, searching specifications for assertions can be a long and tedious process. Having a tool that builds a list of candidate assertions can save a TCK test suite developer a lot of time and effort.
Sun Microsystems recommends that the specification for a Java technology API consist of the Javadoc tag comments that are in the Java source files for the API, along with any other supporting documentation. By default, the Spec Trac tool is designed to handle specifications in this format; in fact, when you use the Spec Trac tool to identify candidate assertions, the tool runs the Javadoc tool. You can however customize the Spec Trac tool for use with other specification formats. What this means is that unless you customize it, Spec Trac expects as input source files that are acceptable to the Javadoc tool, for example, Java source files that contain Javadoc tag comments. The Spec Trac tool also expects the specification to have a tree-like structure where the specifications for a class are in a directory below the specifications for its package.
Let's use the Spec Trac tool to identify candidate assertions in the specification
for the Before running the Spec Trac tool, let's set up its operating environment. The Spec Trac tool requires Java 2 Platform, Standard Edition (J2SE) SDK v 1.3, and runs in any platform in which the J2SE v 1.3 SDK is available, such as the Solaris Operating Environment or the Windows NT platform.
Before you use the tool, you need to make sure that:
Now that the environment is set up, let's run the Spec Trac tool.
Assume for the purposes of this example that the source file for
the
java com.sun.tdk.spectrac.Main getassert \ -sourcepath /usr/local/src java.io.BufferedInputStream The results are then displayed in the standard output stream. Notice that each line of the result looks something like this:
<java.io|BufferedInputStream 99341f97> A BufferedInputStream ...
Notice too that the result includes candidate assertions for the
<java.io|BufferedInputStream.read(byte[],int,int) 23647791> Reads bytes from this byte-input stream into the ...
The information between the angle brackets is an assertion ID, comprised of a signature followed
by a hexadecimal value. The signature identifies the package and the class, interface, method, or field
associated with the assertion. In this example, the assertion ID
You can also use the
java com.sun.tdk.spectrac.Main getassert \ -sourcepath /usr/local/src java.io javax.microedition.ioThe candidate assertion list for a package or set of packages can be very large, so you have the added option of directing the list of candidate assertions to a file. For example, the following command returns the candidate assertions for the java.io package in a file named java.io.assert. (Spec Trac
automatically assigns output files an extension of assert). The file will
be placed in the /usr/local/test/assertions directory, because that's what
is specified in the -precompilepath option:
java com.sun.tdk.spectrac.Main getassert \ -sourcepath /usr/local/src \ -precompilepath /usr/local/test/assertions \ java.io With the candidate assertions identified by the Spec Trac tool, a TCK test suite developer then verifies that the candidates are indeed assertions, and that they are testable. The test suite developer also needs to determine if any assertions need to be added (remember, the tool does not identify implied assertions). The next step is to create the test cases for the testable assertions. How to create test cases is beyond the scope of this article; for detailed information on how to create test cases for a TCK see the Java Technology Test Suite Development Guide. After a test suite developer creates the test cases, he or she can use the Test Generation tool provided in the Java Compatibility Test Tools to help turn the test cases into a TCK test suite for use with the JavaTest harness. The Test Generation tool will be covered in a future article. Using Spec Trac to Report on TCK Test Case CoverageAfter identifying the candidate assertions in a specification, and building a TCK test suite to test assertions, a TCK test suite developer can use the Spec Trac tool to report on the extent of test case coverage. For example, he or she can use the Spec Trac tool to determine which candidate assertions for a class are covered by test cases, and which are not.
In order to produce a report, the Spec Trac tool needs access to information that binds test cases to candidate assertions. A test suite developer needs to provide this binding in a file called a TCK information file. Each line in the TCK information file must be in the following format: [testID] assertionID [assertion]
where testID is a test case identifier, assertionID is the assertion ID, and
assertion is the text of the assertion. The test case identifier is any indicator
that uniquely identifies the TCK test case. For example, if the test case is developed for
use with the JavaTest harness, the test case identifier uniquely identifies a test case by
conforming to the JavaTest format; this might be the name of an HTML file,
such as (
The assertion ID and assertion text are the same pieces of information that form each line of
output produced by the
For example, assume that the test cases for the
To report on test case coverage, use the Spec Trac tool command java com.sun.tdk.spectrac.Main report \ -s -workspace /usr/local/test \ -precompilepath /usr/local/test/assertions \ java.io.BufferedInputStream The result might look something like this:
The results indicate that 98% of the candidate assertions identified in the Javadoc comments
for the
To get a list of candidate assertions
that are not covered by test cases, specify the java com.sun.tdk.spectrac.Main report \ -u -workspace /usr/local/test \ -precompilepath /usr/local/test/assertions \ java.io.BufferedInputStream The result might look something like this:
Other options allow you to request a list of candidate assertions that are
covered by test cases ( java com.sun.tdk.spectrac.Main report \ -t -workspace /usr/local/test \ -precompilepath /usr/local/test/assertions \ java.io.BufferedInputStream And here is the result (only the first two items in the list are shown):
Notice that in all the report examples, the test cases are in a directory that
matches the fully-qualified name of the tested class. In other words, the test cases for the
You can also couple in one command a request to build a list of candidate assertions,
and report on test case coverage. For example, the following command builds a list
of candidate assertions from the Javadoc specification of the
And, as is the case for candidate assertions, you can direct a report to a file.
For example, the following command lists the assertions that are covered by test cases.
The list will be stored in a file in directory
The Java Community Process Program The Java Community Process - Community Resources - TCK Tool & Info Java Technology Test Suite Development Guide About the AuthorEd Ort is a staff member of the Java Developer Connection. He has written extensively about relational database technology and programming languages. | ||||||||||||||||||||||||
|
| ||||||||||||