use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.
the class BranchNoveltyFunction method getDistance.
@Override
public double getDistance(TestChromosome individual1, TestChromosome individual2) {
ExecutionResult result1 = getExecutionResult(individual1);
ExecutionResult result2 = getExecutionResult(individual2);
ExecutionTrace trace1 = result1.getTrace();
ExecutionTrace trace2 = result2.getTrace();
double difference = 0.0;
for (Integer branch : branches) {
if (trace1.hasTrueDistance(branch) && trace2.hasTrueDistance(branch)) {
double distance1 = trace1.getTrueDistance(branch);
double distance2 = trace2.getTrueDistance(branch);
difference += Math.abs(distance1 - distance2);
} else if (trace1.hasTrueDistance(branch) || trace2.hasTrueDistance(branch)) {
difference += 1.0;
}
}
Set<String> methods1 = trace1.getCoveredBranchlessMethods();
Set<String> methods2 = trace2.getCoveredBranchlessMethods();
for (String branchlessMethod : branchlessMethods) {
if (methods1.contains(branchlessMethod) != methods2.contains(branchlessMethod)) {
difference += 1.0;
}
}
difference /= (branches.size() + branchlessMethods.size());
return difference;
}
use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.
the class DSETestCaseLocalSearch method getCoveredBranches.
/**
* Returns the set of covered branches by this test
*
* @param test
* @return
*/
private static Set<Branch> getCoveredBranches(TestChromosome test) {
final Set<Branch> testCoveredBranches = new HashSet<Branch>();
ExecutionTrace trace = test.getLastExecutionResult().getTrace();
{
Set<Integer> coveredTrueBranchIndexesInTrace = trace.getCoveredTrueBranches();
for (Integer branchIndex : coveredTrueBranchIndexesInTrace) {
Branch b = new Branch(branchIndex, true);
testCoveredBranches.add(b);
}
}
{
Set<Integer> coveredFalseBranchIndexesInTrace = trace.getCoveredFalseBranches();
for (Integer branchIndex : coveredFalseBranchIndexesInTrace) {
Branch b = new Branch(branchIndex, false);
testCoveredBranches.add(b);
}
}
return testCoveredBranches;
}
use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.
the class DeprecatedTestSuiteDSE method getCoveredBranches.
/**
* Returns the set of covered branches by this test
*
* @param test
* @return
*/
private static Set<Branch> getCoveredBranches(TestChromosome test) {
final Set<Branch> testCoveredBranches = new HashSet<Branch>();
ExecutionTrace trace = test.getLastExecutionResult().getTrace();
{
Set<Integer> coveredTrueBranchIndexesInTrace = trace.getCoveredTrueBranches();
for (Integer branchIndex : coveredTrueBranchIndexesInTrace) {
Branch b = new Branch(branchIndex, true);
testCoveredBranches.add(b);
}
}
{
Set<Integer> coveredFalseBranchIndexesInTrace = trace.getCoveredFalseBranches();
for (Integer branchIndex : coveredFalseBranchIndexesInTrace) {
Branch b = new Branch(branchIndex, false);
testCoveredBranches.add(b);
}
}
return testCoveredBranches;
}
use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.
the class InstrumentingClassLoaderTest method testDirectInstrumentation.
@Ignore
@Test
public void testDirectInstrumentation() throws Exception {
Class<?> originalClass = ClassLoaderTestSubject.class;
Properties.TARGET_CLASS = originalClass.getName();
Properties.PROJECT_PREFIX = originalClass.getPackage().getName();
ClassLoaderTestSubject original = new ClassLoaderTestSubject();
ExecutionTracer.enable();
ExecutionTracer.getExecutionTracer().clear();
original.assess(6);
ExecutionTrace execTrace = ExecutionTracer.getExecutionTracer().getTrace();
Assert.assertTrue(execTrace.getTrueDistances().isEmpty());
Assert.assertTrue(execTrace.getFalseDistances().isEmpty());
TestabilityTransformationClassLoader instrumentingClassLoader = new TestabilityTransformationClassLoader();
Class<?> changedClass = instrumentingClassLoader.loadClass(ClassLoaderTestSubject.class.getName());
Assert.assertEquals(instrumentingClassLoader, changedClass.getClassLoader());
Assert.assertTrue(changedClass.hashCode() != originalClass.hashCode());
Assert.assertFalse(changedClass.equals(originalClass));
Object changed = changedClass.getConstructor().newInstance();
try {
@SuppressWarnings("unused") ClassLoaderTestSubject casted = (ClassLoaderTestSubject) changed;
Assert.fail();
} catch (ClassCastException exc) {
// expected
}
ExecutionTracer.getExecutionTracer().clear();
TestUtil.invokeMethod(changed, "assess", Integer.valueOf(6));
execTrace = ExecutionTracer.getExecutionTracer().getTrace();
Assert.assertFalse(execTrace.getTrueDistances().isEmpty());
Assert.assertFalse(execTrace.getFalseDistances().isEmpty());
ExecutionTracer.getExecutionTracer().clear();
}
use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.
the class InstrumentingClassLoaderTest method testDependingInstrumentation.
/*
* Tests the child-first/parent-last property of the classloader.
*/
@Ignore
@Test
public void testDependingInstrumentation() throws Exception {
Class<?> originalClass = DependentClassLoaderTestSubject.class;
Properties.TARGET_CLASS = originalClass.getName();
Properties.PROJECT_PREFIX = originalClass.getPackage().getName();
Properties.TARGET_CLASS_PREFIX = Properties.PROJECT_PREFIX;
TestabilityTransformationClassLoader instrumentingClassLoader = new TestabilityTransformationClassLoader();
Class<?> changedClass = instrumentingClassLoader.loadClass(ClassLoaderTestSubject.class.getName());
Assert.assertEquals(instrumentingClassLoader, changedClass.getClassLoader());
Object changed = changedClass.getConstructor().newInstance();
ExecutionTracer.enable();
ExecutionTracer.getExecutionTracer().clear();
TestUtil.invokeMethod(changed, "trySomethingElse");
ExecutionTrace execTrace = ExecutionTracer.getExecutionTracer().getTrace();
execTrace = ExecutionTracer.getExecutionTracer().getTrace();
Assert.assertFalse(execTrace.getTrueDistances().isEmpty());
Assert.assertFalse(execTrace.getFalseDistances().isEmpty());
ExecutionTracer.getExecutionTracer().clear();
}
Aggregations