Extracting Test Assertions from a Specification

W3C Editor's Draft 08 December 2009

This Version:
Latest Published Version:
Latest Editor's Draft:
Previous version:
Dominique Hazaël-Massieux, W3C


This document describes a methodology that was used successfully to define, extract and maintain test assertions from a W3C specification in synchronization with its test suite.

Status of This Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This document was published by the Mobile Web Initiative Test Suites Working Group as an Editor's Draft. If you wish to make comments regarding this document, please send them to public-mwts@w3.org (subscribe, archives). All feedback is welcome.

Publication as a Editor's Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

Table of Contents

1. Introduction

The Mobile Web Test Suites Working Group worked with the editors of Widgets family of specifications in the Web Applications Working Group on a methodology that has allowed to automate the extraction of test assertions from their specifications, and their maintenance in parallel to the building of the test suite.

2. Making the specification testable

Most W3C specifications use the RFC 2119 [RFC2119] keywords (must, should, may, etc.) to indicate the level of requirement that is imposed on an implementation of the specification.

Taking an example from the Widgets Packaging and Configuration [WIDGETS] specification:

If a user agent encounters a file matching a file name given in the file name column of the default start files table in an arbitrary folder, then the user agent must treat that file as an arbitrary file.

After following the definitions given in the specification, the conformance requirement above can be easily turned into a testable assertion (which itself can be used to derive test cases):

Upon encountering a file matching either index.htm, index.html, index.svg, index.xhtml, or index.xht in a folder different from the root directory and the locales directory, a user agent does not treat this file as a default start file, a default icon, or a configuration file.

Given their similarities, a conformance requirement can be used as an equivalent to a testable assertion, provided it contains all the necessary information to make it testable (see The Structure of a Test Assertion in the Test Assertions Guidelines [OASIS-TAG]), namely:

There are common mistakes in writing conformance requirements that makes them much harder to use as testable assertions, including:

The first step in turning the specification into a useful source of testable assertions is logically to fix as many of these problems as possible. In the process of doing so, it is possible to use specific mark-up conventions that can facilitate the creation and maintenance of the test suite.

3. Mark-up conventions for test assertions

To make it easy to create test cases based on a given test assertion, that test assertion minimally needs:

Using mark-up conventions make it possible to automatically extract the test assertions from the specifications with the required information; re-using the example of test assertion above, the following mark-up highlights the important information:

<p id="ta-RRZxvvTFHx">If a user agent encounters a <a href="#file">file</a> matching a file name given in the file name column of the <a href="#default-start-files-table">default start files table</a> in an <a href="#arbitrary">arbitrary</a> <a href="#folder">folder</a>, then <a class="product-ua" href="#user-agent">user agent</a> <em class="ct">must</em> treat that file as an <a href="#arbitrary">arbitrary</a> file.</p>

That mark-up achieves the following results:

4. Extracting automatically test assertions

There are a number of technologies that can be used to filter an HTML document based on the kind of mark-up conventions described above.

In the course of the co-development of the test suite and the specification, the group and the specification editors used two of these technologies:

The original extraction of test assertions was made through an XSLT style sheet, that allowed to generate a static list of test assertions that served as the first basis for the review of the testability of the specification.

Over time, the extraction system was switched to the JavaScript-based approach, allowing for an easier maintenance of the test plan [WIDGETS-TESTS] where the test assertions could be automatically obtained from the specification, while keeping the rest of the test plan easy to update.

5. Test assertions and test cases

Once the test assertions have been identified and extracted, the work of creating test cases for each test assertion is vastly simplified.

A test writer can look at a given test assertion, create a test case that matches the pre-requisites set in the assertion, and document the expected outcome described by the required behaviour.

Each test case can be associated to a given test assertion ; later on, when running the test suite and finding test cases that fail, it allows to identify very quickly the assertion behind it that was failed, and thus evaluate which of the implementation, the test case or the specification is wrong.

To maintain the association between test cases and test assertions, a simple XML file was set up:

<testsuite for="http://www.w3.org/TR/widgets/">
  <test id="aa"
    src="test-cases/ta-ACCJfDGwDQ/000/aa.wgt"> Tests that
    the UA rejects configuration documents that don't have correct
    widget element at the root. To pass, the UA must treat this as an
    invalid widget (the root element is not widget).></test>

The test element encompasses data about a single test case:

This XML file allows to generate the final round of packaging and information needed for the test suite:

6. Conclusion

While the methodology described above uses three separate steps (making the specification testable, marking it up and linking test assertions to test cases), these steps don't have to be applied sequentially, and have shown in practice to work best in a more integrated and iterative process.

This methodology has proved very successful for the Widgets Packaging and Configuration specification, and is now being applied to the other Widgets specifications developed by the Web Applications Working Group.

A. References

A.1 Normative references

No normative references.

A.2 Informative references

Stephen D. Green, Dmitry Kostovarov. Test Assertions Guidelines. OASIS Committee Draft (Work in progress) .URL: http://docs.oasis-open.org/tag/guidelines/v1.0/testassertionsguidelines.html
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. Internet RFC 2119. URL: http://www.ietf.org/rfc/rfc2119.txt
Marcos Caceres. Widget Packaging and Configuration. 01 December 2009. W3C Candidate Recommendation. (Work in progress.) URL: http://www.w3.org/TR/2009/CR-widgets-20091201/
Samuel Santos, Daniel Silva, Marcos Caceres. Conformance Matrix for Widgets Packaging and Configuration. (Work in progress.) URL: http://samaxes.svn.beanstalkapp.com/widgets_compatibility_matrix/trunk/index.html
Marcos Caceres, Kai Hendry. Widgets 1.0: Test Suite for Packaging and Configuration. W3C Test Suite. (Work in progress.) URL: http://dev.w3.org/2006/waf/widgets/test-suite/