JET

Package edu.utep.cs.et.rat

Contains the source code to automatically test methods and constructors by generating test cases randomly.

See:
          Description

Interface Summary
Context An interface representing a testing context.
Denotable An interface to uniformly represent various kinds of Java values and objects that can be part of a test case.
MethodWrapper An interface to wrap a Java method or constructor.
TestCaseGenerationListener The listener interface for receiving test case generation events.
ValueFactory An interface to create various kinds of values.
ValueGenerator An interface to generate values of various types.
 

Class Summary
IncrementalRandomTestCaseGenerator A class to generate test cases randomly.
RandomTestCaseGenerator A class to generate test cases randomly for a method or constructor.
TestCase A class to represent a test case.
TestCaseGenerator An abstract class to define the public interface for test case generation and execution.
TestCaseGenerator.TestSuite Test suite class.
TestRunner A class to execute test cases and determine test results.
 

Package edu.utep.cs.et.rat Description

Contains the source code to automatically test methods and constructors by generating test cases randomly. The class under test is assumed to be compiled with the JML compiler (jmlc). The idea is, for a given method or constructor, to generate a test case consisting of a receiver and arguments, of appropriate types. The test result is determined by observing the execution of the method or constructor. In general, if there is no assertion violation, the test succeeds; otherwise, test fails. That is, runtime assertion check is used as a test oracle.

The main interface class of this package is RandomTestCaseGenerator that, for a given method or constructor, generates a set of test cases, performs test execution, and reports the test result for each test case. The class implements the Observer design pattern to report test cases and results to the caller, as shown in the sample code below.

import edu.utep.cs.et.rat.*;
import java.lang.reflect.*;

public class Sample {

  /** Sample method to be tested. */
  //@ requires x > 0;
  //@ ensures \result > 0;
  public int doSomething(int x) {
    // do something useful with x.
    return x - 10;
  }

  public static void main(String [] args) {

    // create a test case generator
    TestCaseGenerator tgen = new RandomTestCaseGenerator();

    // register an observer to print test results with test cases
    tgen.addTestCaseGenerationListener(
      new TestCaseGenerationListener() {
        public void successTestCase(TestCase tc) {
          System.out.println("Success: " + tc);
        }
        public void failureTestCase(TestCase tc) {
          System.out.println("Failure: " + tc);
        }
        public void meaninglessTestCase(TestCase tc) {
          System.out.println("Meaningless: " + tc);
        }
      });

    // retrieve the doSomthing method
    Method meth = null;
    try {
      meth = Sample.class.getMethod("doSomthing", new Class[] {Integer.TYPE});
    } catch (NoSuchMethodException e) {
    }

    // test the doSomthing method
    tgen.generate(meth);
  }
}

The sample code above:

  1. creates an instance of RandomTestCaseGenerator,
  2. creates and registers a TestCaseGenerationListener to observe the generated test cases and their test results,
  3. retrieves the method to be tested (i.e., doSomthing) using the Java's reflection facility, and
  4. calls the generate method to perform the actual testing.


JET

JET is Copyright (C) 2005-2007 by The University of Texas at El Paso and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.