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;
}
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;
}
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;
}
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();
}
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;
}
Aggregations