use of org.evosuite.testcase.TestChromosome 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;
}
use of org.evosuite.testcase.TestChromosome in project evosuite by EvoSuite.
the class AssertionGenerator method filterFailingAssertions.
public void filterFailingAssertions(TestSuiteChromosome testSuite) {
List<TestChromosome> tests = testSuite.getTestChromosomes();
for (TestChromosome test : tests) {
filterFailingAssertions(test.getTestCase());
}
// Execute again in different order
Randomness.shuffle(tests);
for (TestChromosome test : tests) {
filterFailingAssertions(test.getTestCase());
}
}
use of org.evosuite.testcase.TestChromosome in project evosuite by EvoSuite.
the class AssertionGenerator method changeClassLoader.
protected void changeClassLoader(TestSuiteChromosome suite) {
Sandbox.goingToExecuteSUTCode();
TestGenerationContext.getInstance().goingToExecuteSUTCode();
Sandbox.goingToExecuteUnsafeCodeOnSameThread();
try {
TestGenerationContext.getInstance().resetContext();
TestGenerationContext.getInstance().goingToExecuteSUTCode();
// We need to reset the target Class since it requires a different instrumentation
// for handling assertion generation.
Properties.resetTargetClass();
Properties.getInitializedTargetClass();
ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Mutants, MutationPool.getMutantCounter());
for (TestChromosome test : suite.getTestChromosomes()) {
DefaultTestCase dtest = (DefaultTestCase) test.getTestCase();
dtest.changeClassLoader(TestGenerationContext.getInstance().getClassLoaderForSUT());
// clears cached results
test.setChanged(true);
test.clearCachedMutationResults();
}
} catch (Throwable e) {
LoggingUtils.getEvoLogger().error("* Error while initializing target class: " + (e.getMessage() != null ? e.getMessage() : e.toString()));
logger.error("Problem for " + Properties.TARGET_CLASS + ". Full stack:", e);
} finally {
TestGenerationContext.getInstance().doneWithExecutingSUTCode();
Sandbox.doneWithExecutingUnsafeCodeOnSameThread();
Sandbox.doneWithExecutingSUTCode();
TestGenerationContext.getInstance().doneWithExecutingSUTCode();
}
}
use of org.evosuite.testcase.TestChromosome in project evosuite by EvoSuite.
the class LineCoverageSuiteFitness method analyzeTraces.
/**
* Iterate over all execution results and summarize statistics
*
* @param results
* @param coveredLines
* @return
*/
private boolean analyzeTraces(List<ExecutionResult> results, Set<Integer> coveredLines) {
boolean hasTimeoutOrTestException = false;
for (ExecutionResult result : results) {
if (result.hasTimeout() || result.hasTestException()) {
hasTimeoutOrTestException = true;
continue;
}
TestChromosome test = new TestChromosome();
test.setTestCase(result.test);
test.setLastExecutionResult(result);
test.setChanged(false);
for (Integer goalID : this.lineGoals.keySet()) {
TestFitnessFunction goal = this.lineGoals.get(goalID);
// archive is updated by the TestFitnessFunction class
double fit = goal.getFitness(test, result);
if (fit == 0.0) {
// helper to count the number of covered goals
coveredLines.add(goalID);
// goal to not be considered by the next iteration of the evolutionary algorithm
this.toRemoveLines.add(goalID);
}
}
}
return hasTimeoutOrTestException;
}
use of org.evosuite.testcase.TestChromosome in project evosuite by EvoSuite.
the class MethodCoverageSuiteFitness method analyzeTraces.
/**
* Iterate over all execution results and summarize statistics
*
* @param results
* @param calledMethods
* @return
*/
protected boolean analyzeTraces(List<ExecutionResult> results, Set<String> calledMethods) {
boolean hasTimeoutOrTestException = false;
for (ExecutionResult result : results) {
if (result.hasTimeout() || result.hasTestException()) {
hasTimeoutOrTestException = true;
continue;
}
TestChromosome test = new TestChromosome();
test.setTestCase(result.test);
test.setLastExecutionResult(result);
test.setChanged(false);
for (String methodName : this.methodCoverageMap.keySet()) {
TestFitnessFunction goal = this.methodCoverageMap.get(methodName);
// archive is updated by the TestFitnessFunction class
double fit = goal.getFitness(test, result);
if (fit == 0.0) {
// helper to count the number of covered goals
calledMethods.add(methodName);
// goal to not be considered by the next iteration of the evolutionary algorithm
this.toRemoveMethods.add(methodName);
}
}
// In case there were exceptions in a constructor
handleConstructorExceptions(test, result, calledMethods);
}
return hasTimeoutOrTestException;
}
Aggregations