Package randoop.test
Class ContractCheckingGenerator
java.lang.Object
randoop.test.TestCheckGenerator
randoop.test.ContractCheckingGenerator
An execution visitor that generates checks for error-revealing tests.
If execution of the visited sequence is normal, it will generate checks for contracts over the
values from the execution. Contracts will be checked on all values except for boxed primitives or
Strings. For each contract violation, the visitor adds a Check
to the TestChecks
object that is returned.
If the execution throws an exception considered to be an error, the visitor generates a
NoExceptionCheck
indicating that the statement should not throw the exception.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionContractCheckingGenerator
(ContractSet contracts) Create a new visitor that checks the given contracts after the last statement in a sequence is executed. -
Method Summary
Modifier and TypeMethodDescription(package private) Check
checkContracts
(List<ObjectContract> contracts, ExecutableSequence eseq, TupleSet<ReferenceValue> tuples) If a contract fails for some tuple, returns some such failing check.TestChecks<?>
Generate aTestChecks
object for the executed sequenceeseq
based on the criteria of this generator.private static Object[]
getValues
(List<ReferenceValue> tuple) Creates anObject
array for the given value list.private TestChecks<?>
singletonTestCheck
(Check check) Return a TestChecks that contains only the given check.static boolean
typesMatch
(TypeTuple inputTypes, List<ReferenceValue> valueTuple) Indicates whether the given list of values matches the types in the type tuple.Methods inherited from class randoop.test.TestCheckGenerator
hasGenerator
-
Field Details
-
contracts
-
-
Constructor Details
-
ContractCheckingGenerator
Create a new visitor that checks the given contracts after the last statement in a sequence is executed.- Parameters:
contracts
- expected to be unary contracts, i.e. for each contractc
,c.getArity() == 1
.
-
-
Method Details
-
generateTestChecks
Generate aTestChecks
object for the executed sequenceeseq
based on the criteria of this generator.Adds checks to final statement of sequence. Looks for failure exceptions, and violations of contracts in
contracts
.- Specified by:
generateTestChecks
in classTestCheckGenerator
- Parameters:
eseq
- the sequence for which checks are generated- Returns:
- the generated check set for the sequence
-
singletonTestCheck
Return a TestChecks that contains only the given check.- Parameters:
check
- the sole member of the singleton TestChecks- Returns:
- a TestChecks that contains only the given check
-
checkContracts
Check checkContracts(List<ObjectContract> contracts, ExecutableSequence eseq, TupleSet<ReferenceValue> tuples) If a contract fails for some tuple, returns some such failing check.- Parameters:
contracts
- the contracts to checkeseq
- the executable sequence that is the source of values for checking contractstuples
- the value tuples to use as input to the contracts- Returns:
- a
Check
of the first contract+tuple that did not succeed, or null if all contracts succeeded. More specifically, returns aObjectCheck
if a contract fails, anInvalidExceptionCheck
if a contract throws an exception indicating that the sequence is invalid, null otherwise.
-
typesMatch
Indicates whether the given list of values matches the types in the type tuple. Contracts may have generic input types, so this method checks for consistent substitutions across value types.- Parameters:
inputTypes
- the expected types for contract inputvalueTuple
- the values to match against input types- Returns:
- true if the types of the values are assignable to the expected types, false otherwise
-
getValues
Creates anObject
array for the given value list.- Parameters:
tuple
- the list of values- Returns:
- the Object array for the values
-