Search in sources :

Example 1 with TestCaseExecutor

use of org.evosuite.testcase.execution.TestCaseExecutor in project evosuite by EvoSuite.

the class Contract method fails.

/**
 * Run the test against this contract and determine whether it reports a
 * failure
 *
 * @param test
 *            a {@link org.evosuite.testcase.TestCase} object.
 * @return a boolean.
 */
public boolean fails(TestCase test) {
    ContractChecker.setActive(false);
    TestCaseExecutor executor = TestCaseExecutor.getInstance();
    SingleContractChecker checker = new SingleContractChecker(this);
    executor.addObserver(checker);
    TestCaseExecutor.runTest(test);
    executor.removeObserver(checker);
    // ContractChecker.setActive(true);
    return !checker.isValid();
}
Also used : TestCaseExecutor(org.evosuite.testcase.execution.TestCaseExecutor)

Example 2 with TestCaseExecutor

use of org.evosuite.testcase.execution.TestCaseExecutor in project evosuite by EvoSuite.

the class TestCaseExpander method createConcretePrimitives.

@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
private void createConcretePrimitives(TestCase test) {
    // Execute test to collect concrete values
    TestCaseExecutor executor = TestCaseExecutor.getInstance();
    ConcreteValueObserver observer = new ConcreteValueObserver();
    executor.addObserver(observer);
    executor.execute(test);
    executor.removeObserver(observer);
    // Now replace references to concrete values with new primitive statements
    Map<Integer, Object> concreteValues = observer.getConcreteValues();
    List<Integer> positions = new ArrayList<Integer>(concreteValues.keySet());
    Collections.sort(positions, Collections.reverseOrder());
    for (Integer position : positions) {
        Object value = concreteValues.get(position);
        Statement statement = test.getStatement(position);
        PrimitiveStatement primitive = PrimitiveStatement.getPrimitiveStatement(test, new GenericClass(value.getClass()));
        primitive.setValue(value);
        VariableReference replacement = test.addStatement(primitive, position);
        test.replace(statement.getReturnValue(), replacement);
    }
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) GenericClass(org.evosuite.utils.generic.GenericClass) TestCaseExecutor(org.evosuite.testcase.execution.TestCaseExecutor) ArrayList(java.util.ArrayList)

Example 3 with TestCaseExecutor

use of org.evosuite.testcase.execution.TestCaseExecutor in project evosuite by EvoSuite.

the class ConstantInliner method inline.

/**
 * <p>
 * inline
 * </p>
 *
 * @param test
 *            a {@link org.evosuite.testcase.TestCase} object.
 */
public void inline(TestCase test) {
    this.test = test;
    TestCaseExecutor executor = TestCaseExecutor.getInstance();
    executor.addObserver(this);
    executor.execute(test);
    executor.removeObserver(this);
    removeUnusedVariables(test);
    assert (test.isValid());
}
Also used : TestCaseExecutor(org.evosuite.testcase.execution.TestCaseExecutor)

Aggregations

TestCaseExecutor (org.evosuite.testcase.execution.TestCaseExecutor)3 ArrayList (java.util.ArrayList)1 VariableReference (org.evosuite.testcase.variable.VariableReference)1 GenericClass (org.evosuite.utils.generic.GenericClass)1