use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class StrongMutationTestFitness method runTest.
/**
* {@inheritDoc}
*/
public static ExecutionResult runTest(TestCase test, Mutation mutant) {
ExecutionResult result = new ExecutionResult(test, mutant);
try {
if (mutant != null)
logger.debug("Executing test for mutant " + mutant.getId() + ": \n" + test.toCode());
else
logger.debug("Executing test without mutant");
if (mutant != null)
MutationObserver.activateMutation(mutant);
result = TestCaseExecutor.getInstance().execute(test);
if (mutant != null)
MutationObserver.deactivateMutation(mutant);
int num = test.size();
if (!result.noThrownExceptions()) {
num = result.getFirstPositionOfThrownException();
}
// if (mutant == null)
MaxStatementsStoppingCondition.statementsExecuted(num);
int i = 0;
for (AssertionTraceObserver<?> observer : observers) {
result.setTrace(observer.getTrace(), observerClasses[i++]);
}
} catch (Exception e) {
throw new Error(e);
}
return result;
}
use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class StrongMutationTestFitness method ensureExecutionResultHasTraces.
private void ensureExecutionResultHasTraces(TestChromosome individual, ExecutionResult result) {
if (result.getTraces().isEmpty() && observerClasses.length > 0) {
ExecutionResult newResult = runTest(individual.getTestCase());
for (Class<?> observerClass : observerClasses) {
OutputTrace<?> trace = newResult.getTrace(observerClass);
result.setTrace(trace, observerClass);
}
}
}
use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class RhoCoverageSuiteFitness method getFitness.
protected double getFitness(AbstractTestSuiteChromosome<? extends ExecutableChromosome> suite, boolean updateFitness) {
Set<Set<Integer>> tmp_coverage_matrix = new LinkedHashSet<Set<Integer>>(this.coverage_matrix_generated_so_far);
double fitness = 1.0;
int number_of_goals = RhoCoverageFactory.getNumberGoals();
int number_of_ones = RhoCoverageFactory.getNumber_of_Ones() + this.previous_number_of_ones;
int number_of_test_cases = RhoCoverageFactory.getNumber_of_Test_Cases() + this.previous_number_of_test_cases;
List<ExecutionResult> results = runTestSuite(suite);
for (int i = 0; i < results.size(); i++) {
// Execute test cases and collect the covered lines
ExecutionResult result = results.get(i);
Set<Integer> coveredLines = result.getTrace().getCoveredLines();
if (Properties.STRATEGY == Properties.Strategy.ENTBUG) {
// order set
List<Integer> l_coveredLines = new ArrayList<Integer>(coveredLines);
Collections.sort(l_coveredLines);
Set<Integer> coveredLinesOrdered = new LinkedHashSet<Integer>();
for (Integer coveredLine : l_coveredLines) {
coveredLinesOrdered.add(coveredLine);
}
// no coverage
if (coveredLinesOrdered.size() == 0) {
continue;
} else // already exists locally
if (tmp_coverage_matrix.add(coveredLinesOrdered) == false) {
continue;
} else // already exists on the original test suite
if (RhoCoverageFactory.exists(l_coveredLines)) {
continue;
} else // good
{
number_of_ones += coveredLinesOrdered.size();
number_of_test_cases++;
}
} else {
number_of_ones += coveredLines.size();
number_of_test_cases++;
}
}
// was not possible to generate new test cases
if (number_of_test_cases == 0.0) {
// penalise this suite
fitness = 1.0;
} else {
fitness = ((double) number_of_ones) / ((double) number_of_test_cases) / ((double) number_of_goals);
fitness = Math.abs(0.5 - fitness);
}
if (updateFitness) {
updateIndividual(this, suite, fitness);
}
return fitness;
}
use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class CoverageArchive method addToArchive.
private void addToArchive(F target, T solution) {
this.uncovered.remove(target);
this.covered.put(target, solution);
this.removeNonCoveredTargetOfAMethod(target);
this.hasBeenUpdated = true;
ExecutionResult result = solution.getLastExecutionResult();
if (result != null && (result.hasTimeout() || result.hasTestException())) {
AtMostOnceLogger.warn(logger, "A solution with a timeout/exception result has been added to the archive. The covered goal was " + target.toString());
}
}
use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class IntegerLocalSearch method iterate.
private boolean iterate(long delta, LocalSearchObjective<TestChromosome> objective, TestChromosome test, NumericalPrimitiveStatement<T> p, int statement) {
boolean improvement = false;
T oldValue = p.getValue();
ExecutionResult oldResult = test.getLastExecutionResult();
p.increment(delta);
logger.info("Trying increment " + delta + " of " + p.getCode());
while (objective.hasImproved(test)) {
oldValue = p.getValue();
oldResult = test.getLastExecutionResult();
improvement = true;
delta = 2 * delta;
p.increment(delta);
logger.info("Trying increment " + delta + " of " + p.getCode());
}
logger.info("No improvement on " + p.getCode());
p.setValue(oldValue);
test.setLastExecutionResult(oldResult);
test.setChanged(false);
logger.info("Final value of this iteration: " + p.getValue());
return improvement;
}
Aggregations