use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.
the class TestExecutionTracer method testLesserThan.
@Ignore
@Test
public void testLesserThan() {
final Integer branchId = 4;
final String methodName = "lesserThan_IF_CMPGE";
ExecutionTrace execTrace = execute(methodName, 5, 5);
Assert.assertEquals(methodName + signature, BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranch(branchId).getMethodName());
Assert.assertEquals(0.0, execTrace.getTrueDistance(branchId), 1.0);
Assert.assertEquals(0.0, execTrace.getFalseDistance(branchId), 0.0);
execTrace = execute(methodName, 5, 6);
Assert.assertEquals(0.0, execTrace.getTrueDistance(branchId), 0.0);
Assert.assertEquals(0.0, execTrace.getFalseDistance(branchId), 1.0);
}
use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.
the class TestExecutionTracer method testGreaterThan.
@Ignore
@Test
public void testGreaterThan() {
final Integer branchId = 2;
final String methodName = "greaterThan_IF_CMPLE";
ExecutionTrace execTrace = execute(methodName, 5, 5);
Assert.assertEquals(methodName + signature, BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranch(branchId).getMethodName());
Assert.assertEquals(1.0, execTrace.getTrueDistance(branchId), DELTA);
Assert.assertEquals(0.0, execTrace.getFalseDistance(branchId), DELTA);
execTrace = execute(methodName, 6, 5);
Assert.assertEquals(0.0, execTrace.getTrueDistance(branchId), DELTA);
Assert.assertEquals(1.0, execTrace.getFalseDistance(branchId), DELTA);
}
use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.
the class TestExecutionTracer method testGreaterEqual.
@Ignore
@Test
public void testGreaterEqual() {
final Integer branchId = 1;
final String methodName = "greaterEqual_IF_CMPLT";
ExecutionTrace execTrace = execute(methodName, 5, 5);
Assert.assertEquals(methodName + signature, BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranch(branchId).getMethodName());
Assert.assertEquals(0.0, execTrace.getTrueDistance(branchId), DELTA);
Assert.assertEquals(1.0, execTrace.getFalseDistance(branchId), DELTA);
execTrace = execute(methodName, 5, 6);
Assert.assertEquals(1.0, execTrace.getTrueDistance(branchId), DELTA);
Assert.assertEquals(0.0, execTrace.getFalseDistance(branchId), DELTA);
}
use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.
the class TestExecutionTracer method execute.
private ExecutionTrace execute(String methodName, Integer val1, Integer val2) {
try {
ExecutionTracer.enable();
Class<?> targetClass = classTransformer.instrumentClass(fullyQualifiedTargetClass);
Constructor<?> constructor = targetClass.getConstructor();
Object target = constructor.newInstance();
Method method = targetClass.getMethod(methodName, Integer.class, Integer.class);
method.invoke(target, val1, val2);
ExecutionTrace execTrace = ExecutionTracer.getExecutionTracer().getTrace();
ExecutionTracer.getExecutionTracer().clear();
return execTrace;
} catch (Exception exc) {
throw new RuntimeException(exc);
}
}
use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.
the class ClassReInitializer method reInitializeClassesAfterTestExecution.
/**
* This method is invoked after a test execution has ended. The classes to
* be resetted will depend on the value of the reset_a
*
* @param executedTestCase
* @param testCaseResult
*/
public void reInitializeClassesAfterTestExecution(TestCase executedTestCase, ExecutionResult testCaseResult) {
// first collect the initialized classes during this test execution
final ExecutionTrace trace = testCaseResult.getTrace();
List<String> classesInitializedDuringTestExecution = trace.getInitializedClasses();
this.addInitializedClasses(classesInitializedDuringTestExecution);
// re-initialized. Therefore, we should return
if (initializedClasses.isEmpty()) {
return;
} else {
// second, re-initialize classes
if (reset_all_observed_classes) {
ClassReInitializeExecutor.getInstance().resetClasses(initializedClasses);
} else {
// reset only classes that were "observed" to have some
// GETSTATIC/PUTSTATIC updating their state during test
// execution
List<String> classesToReset = new LinkedList<String>();
classesToReset.addAll(trace.getClassesWithStaticWrites());
if (Properties.RESET_STATIC_FIELD_GETS) {
classesToReset.addAll(trace.getClassesWithStaticReads());
}
HashSet<String> moreClassesForReset = getMoreClassesToReset(executedTestCase, testCaseResult);
classesToReset.addAll(moreClassesForReset);
// sort classes to reset
Collections.sort(classesToReset);
ClassLoader loader = null;
if (executedTestCase instanceof DefaultTestCase) {
DefaultTestCase defaultTestCase = (DefaultTestCase) executedTestCase;
ClassLoader changedClassLoader = defaultTestCase.getChangedClassLoader();
if (changedClassLoader != null) {
loader = changedClassLoader;
}
}
if (loader == null) {
ClassReInitializeExecutor.getInstance().resetClasses(classesToReset);
} else {
ClassReInitializeExecutor.getInstance().resetClasses(classesToReset, loader);
}
}
}
}
Aggregations