Search in sources :

Example 41 with ExecutionResult

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

the class FloatLocalSearch method iterate.

private boolean iterate(double delta, double factor, LocalSearchObjective<TestChromosome> objective, TestChromosome test, NumericalPrimitiveStatement<T> p, int statement) {
    boolean improvement = false;
    T oldValue = p.getValue();
    ExecutionResult oldResult = test.getLastExecutionResult();
    logger.info("Trying increment " + delta + " of " + p.getCode());
    p.increment(delta);
    while (objective.hasImproved(test)) {
        oldValue = p.getValue();
        oldResult = test.getLastExecutionResult();
        test.setChanged(false);
        improvement = true;
        delta = factor * delta;
        // if (delta > 1)
        // return improvement;
        logger.info("Trying increment " + delta + " of " + p.getCode());
        p.increment(delta);
    }
    p.setValue(oldValue);
    test.setLastExecutionResult(oldResult);
    test.setChanged(false);
    return improvement;
}
Also used : ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Example 42 with ExecutionResult

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

the class EnumLocalSearch method doSearch.

/* (non-Javadoc)
	 * @see org.evosuite.testcase.LocalSearch#doSearch(org.evosuite.testcase.TestChromosome, int, org.evosuite.ga.LocalSearchObjective)
	 */
/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public boolean doSearch(TestChromosome test, int statement, LocalSearchObjective<TestChromosome> objective) {
    EnumPrimitiveStatement p = (EnumPrimitiveStatement) test.getTestCase().getStatement(statement);
    ExecutionResult oldResult = test.getLastExecutionResult();
    oldValue = p.getValue();
    for (Object value : p.getEnumValues()) {
        p.setValue(value);
        if (!objective.hasImproved(test)) {
            // Restore original
            p.setValue(oldValue);
            test.setLastExecutionResult(oldResult);
            test.setChanged(false);
        } else {
            logger.debug("Finished local search with result " + p.getCode());
            return true;
        }
    }
    return false;
}
Also used : EnumPrimitiveStatement(org.evosuite.testcase.statements.EnumPrimitiveStatement) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Example 43 with ExecutionResult

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

the class TestSuiteFitnessFunction method runTestSuite.

/**
 * <p>
 * runTestSuite
 * </p>
 *
 * @param suite
 *            a {@link org.evosuite.testsuite.AbstractTestSuiteChromosome}
 *            object.
 * @return a {@link java.util.List} object.
 */
protected List<ExecutionResult> runTestSuite(AbstractTestSuiteChromosome<? extends ExecutableChromosome> suite) {
    List<ExecutionResult> results = new ArrayList<ExecutionResult>();
    for (ExecutableChromosome chromosome : suite.getTestChromosomes()) {
        // Only execute test if it hasn't been changed
        if (chromosome.isChanged() || chromosome.getLastExecutionResult() == null) {
            ExecutionResult result = chromosome.executeForFitnessFunction(this);
            if (result != null) {
                results.add(result);
                // .clone();
                chromosome.setLastExecutionResult(result);
                chromosome.setChanged(false);
            }
        } else {
            results.add(chromosome.getLastExecutionResult());
        }
    }
    suite.setChanged(false);
    return results;
}
Also used : ExecutableChromosome(org.evosuite.testcase.ExecutableChromosome) ArrayList(java.util.ArrayList) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Example 44 with ExecutionResult

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

the class MockJOptionPaneTest method testInlinerBug.

@Test
public void testInlinerBug() throws Exception {
    Properties.TIMEOUT = Integer.MAX_VALUE;
    InstrumentingClassLoader cl = new InstrumentingClassLoader();
    TestCase t0 = buildTestCase0(cl);
    TestCase t1 = buildTestCase1(cl);
    TestSuiteChromosome suite = new TestSuiteChromosome();
    suite.addTest(t0);
    suite.addTest(t1);
    System.out.println(suite.toString());
    BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
    ff.getFitness(suite);
    ConstantInliner inliner = new ConstantInliner();
    inliner.inline(suite);
    System.out.println(suite.toString());
    List<ExecutionResult> execResults = suite.getLastExecutionResults();
    assertEquals(2, execResults.size());
    ExecutionResult r1 = execResults.get(0);
    ExecutionResult r2 = execResults.get(1);
    r1.calledReflection();
    r2.calledReflection();
}
Also used : ConstantInliner(org.evosuite.testcase.ConstantInliner) TestCase(org.evosuite.testcase.TestCase) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult) InstrumentingClassLoader(org.evosuite.instrumentation.InstrumentingClassLoader) Test(org.junit.Test)

Example 45 with ExecutionResult

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

the class CoverageAnalysis method getCoveredGoals.

/**
 * Return the number of covered goals
 *
 * @param testClass
 * @param allGoals
 * @return
 */
public static Set<TestFitnessFunction> getCoveredGoals(Class<?> testClass, List<TestFitnessFunction> allGoals) {
    // A dummy Chromosome
    TestChromosome dummy = new TestChromosome();
    dummy.setChanged(false);
    // Execution result of a dummy Test Case
    ExecutionResult executionResult = new ExecutionResult(dummy.getTestCase());
    Set<TestFitnessFunction> coveredGoals = new HashSet<TestFitnessFunction>();
    List<JUnitResult> results = executeTests(testClass);
    for (JUnitResult testResult : results) {
        executionResult.setTrace(testResult.getExecutionTrace());
        dummy.setLastExecutionResult(executionResult);
        for (TestFitnessFunction goal : allGoals) {
            if (coveredGoals.contains(goal))
                continue;
            else if (goal.isCovered(dummy))
                coveredGoals.add(goal);
        }
    }
    return coveredGoals;
}
Also used : TestFitnessFunction(org.evosuite.testcase.TestFitnessFunction) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult) TestChromosome(org.evosuite.testcase.TestChromosome)

Aggregations

ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)93 TestChromosome (org.evosuite.testcase.TestChromosome)33 HashSet (java.util.HashSet)15 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)15 ArrayList (java.util.ArrayList)11 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)10 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)9 TestCase (org.evosuite.testcase.TestCase)9 VariableReference (org.evosuite.testcase.variable.VariableReference)9 Test (org.junit.Test)9 LinkedHashSet (java.util.LinkedHashSet)8 HashMap (java.util.HashMap)7 LinkedHashMap (java.util.LinkedHashMap)7 TestCaseBuilder (org.evosuite.symbolic.TestCaseBuilder)7 ArrayReference (org.evosuite.testcase.variable.ArrayReference)7 Set (java.util.Set)6 AbstractTestSuiteChromosome (org.evosuite.testsuite.AbstractTestSuiteChromosome)6 Map (java.util.Map)4 Entry (java.util.Map.Entry)3 ExecutionTrace (org.evosuite.testcase.execution.ExecutionTrace)3