Last updated January 18, 2011 13:12, by Jørgen Austvik
Feedicon  

How to write a Test

A JET test is a XML file which defines how what the test should do.

There are many example tests in the jet source code, e.g. under jet~framework/jet-examples/src/test/jet/*.xml

Anatomy of a Test XML file

The definition of the JET XML file format is defined in jet~framework/dtd/jet-test.dtd (DTD) and jet~framework/dtd/jet-test.xsd (XML Schema). You can use a normal XML validation program to check you test definition against these to check you file.

A simple test looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<Test maxduration="2" xmlns="http://kenai.com/projects/jet" version="1.0">
    <TestDescription ...>
    </TestDescription>
    <TestSetup ...>
        <Binding .../>
        <TestSuite ...>
            <TestCase .../>
            <TestCase .../>
        </TestSuite>
    </TestSetup>
</Test>

Elements

The XML file contains many elements, here is a description of them.

Test

This is the outermost element in the XML file, it contains the other elements.

Parameters:

maxduration
How long this test should maximal run, in minutes, to catch timeouts

TestDescription

Information about this test, can have several sub-elements, non of which are required:

  • Category - special
  • Objective - markup
  • Coverage - text
  • Behaviour - text
  • Prerequisites - text
  • Input - text
  • Output - text
  • PassCriteria - text
  • Requirements - special
  • Description - markup
  • EnvironmentalReq - markup
  • FailCriteria? - markup

Those marked with text take pure text. Example:

  <Coverage>Some text</Coverage>

Those marked with markup take pure text, LINK, B, I, U, P and BR tags.

  • B - bold
  • I - italics
  • U - underline
  • LINK - link, parameter: target
  • P - paragraph
  • BR - break

The Category element is special as it does not take text, but has two attributes: primary and secondary for primary and secondary attributes.

The Requirements element is special, as it takes markup, and a Requirement element in addition. The Requirement element take full markup, and has many attributes (ref, docRef, reqRef, comment, ...). Example:

  <Requirements>
    <B>Many</B> requirements:
    <Requirement ref="NF-1">Lots of speed</Requirement>
    <Requirement ref="NF-2">NO resource usage</Requirement>
  </Requirements>

Binding

Binding elements let you set property values for a test setup, test suite or test case.

Attributes:

key
The attribute key
value
The attribute value
comment
Comment for this setting, optional

Example:

  <TestCase ...>
    <Binding key="jet.timeout" value="true" comment="time out in this test case"/>
  </TestCase>

TestSetup

A test setup is code that runs before and after test cases. Normally this is done to start the software under testing, and stop it after the test runs.

Attributes

class
The name of the Java class that is this setup
name
A name for this setup, optional
comment
A comment for this setup, optional

Example:

<TestSetup class="com.name.product.ProductTestSetup">
  <Binding comment="for this test setup"/>
  <TestSuite>
    <TestCase .../>
    <TestCase .../>
  </TestSuite>
</TestSetup>

The ProductTestSetup class in the example above must inherit com.sun.jet.framework.TestSetup.

TestSuite

A test suite is just a ordered collection of test cases. It contains test setups and test suites.

Attributes:

repeat
How many times to repeat the tests in this test suite, default 1

Example

  <TestSuite repeat="4">
    <TestCase .../>
    <TestCase .../>
  </TestSuite>

Test Case

Test cases run a single test method in a single class. The class should inherit com.sun.jet.framework.TestCase.

Attributes

class
The class where the test method lives
method
The test method to call. This must take no parameters and can throw any exception
name
Name of this test case, optional
comment
Comment for this test case, optional
driver
Which driver to use to run this test, jet is default, can also be junit to run a pure JUnit test.
repeat
The number of times to run this test, default 1

Example

<TestCase class="com.sun.jet.examples.SimpleJetTestCase"
          method="testHelloWorld"
          comment="Simple HelloWorld test case"
          repeat="3"/>

  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close