use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class TestDefaultValue method testCharacter.
@Test
public void testCharacter() throws SecurityException, NoSuchMethodException {
TestCaseBuilder builder = new TestCaseBuilder();
ArrayReference characterArray0 = builder.appendArrayStmt(Character[].class, 10);
VariableReference character0 = builder.appendNull(Character.class);
builder.appendAssignment(characterArray0, 0, character0);
builder.appendAssignment(character0, characterArray0, 0);
builder.appendMethod(character0, Character.class.getMethod("toString"));
DefaultTestCase tc = builder.getDefaultTestCase();
ExecutionResult ret_val = TestCaseExecutor.runTest(tc);
assertNotNull(ret_val);
assertFalse(ret_val.explicitExceptions.isEmpty());
}
use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class TestDefaultValue method testDouble.
@Test
public void testDouble() throws SecurityException, NoSuchMethodException {
TestCaseBuilder builder = new TestCaseBuilder();
ArrayReference doubleArray0 = builder.appendArrayStmt(Double[].class, 10);
VariableReference double0 = builder.appendNull(Double.class);
builder.appendAssignment(doubleArray0, 0, double0);
builder.appendAssignment(double0, doubleArray0, 0);
builder.appendMethod(double0, Double.class.getMethod("floatValue"));
DefaultTestCase tc = builder.getDefaultTestCase();
ExecutionResult ret_val = TestCaseExecutor.runTest(tc);
assertNotNull(ret_val);
assertFalse(ret_val.explicitExceptions.isEmpty());
}
use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class LIPS method runTest.
/**
* This method executes a given test case (i.e., TestChromosome)
*
* @param c test case (TestChromosome) to execute
*/
protected void runTest(T c) {
if (!c.isChanged())
return;
// run the test
TestCase test = ((TestChromosome) c).getTestCase();
ExecutionResult result = TestCaseExecutor.runTest(test);
((TestChromosome) c).setLastExecutionResult(result);
c.setChanged(false);
// notify the fitness evaluation (i.e., the test is executed)
notifyEvaluation(c);
}
use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class BranchesManager method calculateFitness.
public void calculateFitness(T c) {
// run the test
TestCase test = ((TestChromosome) c).getTestCase();
ExecutionResult result = TestCaseExecutor.runTest(test);
((TestChromosome) c).setLastExecutionResult(result);
c.setChanged(false);
if (result.hasTimeout() || result.hasTestException()) {
for (FitnessFunction<T> f : currentGoals) c.setFitness(f, Double.MAX_VALUE);
return;
}
// 1) we update the set of currents goals
Set<FitnessFunction<T>> visitedStatements = new HashSet<FitnessFunction<T>>(uncoveredGoals.size() * 2);
LinkedList<FitnessFunction<T>> targets = new LinkedList<FitnessFunction<T>>();
targets.addAll(this.currentGoals);
while (targets.size() > 0) {
FitnessFunction<T> fitnessFunction = targets.poll();
int past_size = visitedStatements.size();
visitedStatements.add(fitnessFunction);
if (past_size == visitedStatements.size())
continue;
double value = fitnessFunction.getFitness(c);
if (value == 0.0) {
updateCoveredGoals(fitnessFunction, c);
for (FitnessFunction<T> child : graph.getStructuralChildren(fitnessFunction)) {
targets.addLast(child);
}
} else {
currentGoals.add(fitnessFunction);
}
}
currentGoals.removeAll(coveredGoals.keySet());
// 2) we update the archive
for (Integer branchid : result.getTrace().getCoveredFalseBranches()) {
FitnessFunction<T> branch = this.branchCoverageFalseMap.get(branchid);
if (branch == null)
continue;
updateCoveredGoals((FitnessFunction<T>) branch, c);
}
for (Integer branchid : result.getTrace().getCoveredTrueBranches()) {
FitnessFunction<T> branch = this.branchCoverageTrueMap.get(branchid);
if (branch == null)
continue;
updateCoveredGoals((FitnessFunction<T>) branch, c);
}
for (String method : result.getTrace().getCoveredBranchlessMethods()) {
FitnessFunction<T> branch = this.branchlessMethodCoverageMap.get(method);
if (branch == null)
continue;
updateCoveredGoals((FitnessFunction<T>) branch, c);
}
// debugStructuralDependencies(c);
}
use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class MIOArchive method updateArchive.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public void updateArchive(F target, T solution, double fitnessValue) {
assert target != null;
assert this.archive.containsKey(target);
assert fitnessValue >= 0.0;
T solutionClone = (T) solution.clone();
ExecutionResult executionResult = solutionClone.getLastExecutionResult();
// remove all statements after an exception
if (!executionResult.noThrownExceptions()) {
solutionClone.getTestCase().chop(executionResult.getFirstPositionOfThrownException() + 1);
}
boolean isNewCoveredTarget = this.archive.get(target).addSolution(1.0 - FitnessFunction.normalize(fitnessValue), solutionClone);
if (isNewCoveredTarget) {
this.removeNonCoveredTargetOfAMethod(target);
this.hasBeenUpdated = true;
}
}
Aggregations