Package randoop.test

Class RegressionCaptureGenerator

java.lang.Object
randoop.test.TestCheckGenerator
randoop.test.RegressionCaptureGenerator

public final class RegressionCaptureGenerator extends TestCheckGenerator
A TestCheckGenerator that records regression checks on the values created by the sequence.

NOTES:

  • Only creates checks over values whose type is primitive or String.
  • Does not create checks for Strings that contain the string ";@" as this is a good indication that at least part of the String came from a call of Object.toString() (e.g. "[[Ljava.lang.Object;@5780d9]" is the string representation of a list containing one Object).
  • Field Details

    • exceptionExpectation

      private ExpectedExceptionCheckGen exceptionExpectation
      The generator for expected exceptions.
    • sideEffectFreeMethodsByType

      private MultiMap<Type,TypedClassOperation> sideEffectFreeMethodsByType
      The map from a type to the set of side-effect-free operations for the type.
    • isAccessible

      private final AccessibilityPredicate isAccessible
      The accessibility predicate.
    • omitMethodsPredicate

      private OmitMethodsPredicate omitMethodsPredicate
      The user-supplied predicate for methods that should not be called.
    • includeAssertions

      private boolean includeAssertions
      Whether to include regression assertions. If false, no assertions are added for sequences whose execution is NormalExecution.
  • Constructor Details

    • RegressionCaptureGenerator

      public RegressionCaptureGenerator(ExpectedExceptionCheckGen exceptionExpectation, MultiMap<Type,TypedClassOperation> sideEffectFreeMethodsByType, AccessibilityPredicate isAccessible, OmitMethodsPredicate omitMethodsPredicate, boolean includeAssertions)
      Create a RegressionCaptureGenerator.
      Parameters:
      exceptionExpectation - the generator for expected exceptions
      sideEffectFreeMethodsByType - the map from a type to the side-effect-free operations for the type
      isAccessible - the accessibility predicate
      omitMethodsPredicate - the user-supplied predicate for methods that should not be called
      includeAssertions - whether to include regression assertions
  • Method Details

    • generateTestChecks

      public RegressionChecks generateTestChecks(ExecutableSequence eseq)
      Generate a TestChecks object for the executed sequence eseq based on the criteria of this generator.

      Iterates over all statements of the sequence to create regression assertions. If visitor is set to include assertions, then assertions are generated for both normal execution and exceptions. A try-catch block is always generated for exceptions, but whether assertions are included is determined by the ExpectedExceptionCheckGen given when creating this visitor.

      Specified by:
      generateTestChecks in class TestCheckGenerator
      Parameters:
      eseq - the sequence for which checks are generated
      Returns:
      the generated check set for the sequence
      Throws:
      Error - if any statement is not executed, or exception occurs before last statement
    • isObjectToString

      private static boolean isObjectToString(TypedClassOperation m)
      Return true if the method is Object.toString (which is nondeterministic for classes that have not overridden it).
      Parameters:
      m - the method to test
      Returns:
      true if the method is Object.toString
    • isAssertableMethod

      public static boolean isAssertableMethod(TypedClassOperation m, OmitMethodsPredicate omitMethodsPredicate, AccessibilityPredicate accessibility)
      Returns true if the given side-effect-free method or constructor can be used in an assertion in Randoop.
      Parameters:
      m - a method or constructor, which must be side-effect-free
      omitMethodsPredicate - the user-supplied predicate for methods and constructors that should not be called
      accessibility - the predicate used to check whether a method or constructor is accessible to call
      Returns:
      whether we can use this method or constructor in a side-effect-free assertion
      Throws:
      IllegalArgumentException - if m is not either a Method or a Constructor