use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class TestDefaultValue method testShort.
@Test
public void testShort() throws SecurityException, NoSuchMethodException {
TestCaseBuilder builder = new TestCaseBuilder();
ArrayReference integerArray0 = builder.appendArrayStmt(Short[].class, 10);
VariableReference integer0 = builder.appendNull(Short.class);
builder.appendAssignment(integerArray0, 0, integer0);
builder.appendAssignment(integer0, integerArray0, 0);
builder.appendMethod(integer0, Short.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 testInteger.
@Test
public void testInteger() throws SecurityException, NoSuchMethodException {
TestCaseBuilder builder = new TestCaseBuilder();
ArrayReference integerArray0 = builder.appendArrayStmt(Integer[].class, 10);
VariableReference integer0 = builder.appendNull(Integer.class);
builder.appendAssignment(integerArray0, 0, integer0);
builder.appendAssignment(integer0, integerArray0, 0);
builder.appendMethod(integer0, Integer.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 testByte.
@Test
public void testByte() throws SecurityException, NoSuchMethodException {
TestCaseBuilder builder = new TestCaseBuilder();
ArrayReference integerArray0 = builder.appendArrayStmt(Byte[].class, 10);
VariableReference integer0 = builder.appendNull(Byte.class);
builder.appendAssignment(integerArray0, 0, integer0);
builder.appendAssignment(integer0, integerArray0, 0);
builder.appendMethod(integer0, Byte.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 AssertionGenerator method runTest.
/**
* Execute a test case on the original unit
*
* @param test
* The test case that should be executed
* @return a {@link org.evosuite.testcase.execution.ExecutionResult} object.
*/
protected ExecutionResult runTest(TestCase test) {
ExecutionResult result = new ExecutionResult(test);
try {
logger.debug("Executing test");
result = TestCaseExecutor.getInstance().execute(test);
int num = test.size();
MaxStatementsStoppingCondition.statementsExecuted(num);
result.setTrace(comparisonObserver.getTrace(), ComparisonTraceEntry.class);
result.setTrace(primitiveObserver.getTrace(), PrimitiveTraceEntry.class);
result.setTrace(inspectorObserver.getTrace(), InspectorTraceEntry.class);
result.setTrace(fieldObserver.getTrace(), PrimitiveFieldTraceEntry.class);
result.setTrace(nullObserver.getTrace(), NullTraceEntry.class);
result.setTrace(sameObserver.getTrace(), SameTraceEntry.class);
if (!Properties.isRegression())
result.setTrace(arrayObserver.getTrace(), ArrayTraceEntry.class);
result.setTrace(arrayLengthObserver.getTrace(), ArrayLengthTraceEntry.class);
result.setTrace(containsTraceObserver.getTrace(), ContainsTraceEntry.class);
} catch (Exception e) {
throw new Error(e);
}
return result;
}
use of org.evosuite.testcase.execution.ExecutionResult in project evosuite by EvoSuite.
the class OutputCoverageSuiteFitness method getFitness.
/**
* {@inheritDoc}
* <p/>
* Execute all tests and count covered output goals
*/
@Override
public double getFitness(AbstractTestSuiteChromosome<? extends ExecutableChromosome> suite) {
logger.trace("Calculating test suite fitness");
double fitness = 0.0;
List<ExecutionResult> results = runTestSuite(suite);
boolean hasTimeoutOrTestException = false;
for (ExecutionResult result : results) {
if (result.hasTimeout() || result.hasTestException()) {
hasTimeoutOrTestException = true;
break;
}
}
Set<TestFitnessFunction> setOfCoveredGoals = new LinkedHashSet<>();
if (hasTimeoutOrTestException) {
logger.info("Test suite has timed out, setting fitness to max value " + totalGoals);
fitness = totalGoals;
} else
fitness = computeDistance(results, setOfCoveredGoals);
int coveredGoals = setOfCoveredGoals.size() + removedGoals.size();
if (totalGoals > 0)
suite.setCoverage(this, (double) coveredGoals / (double) totalGoals);
else
suite.setCoverage(this, 1.0);
suite.setNumOfCoveredGoals(this, coveredGoals);
printStatusMessages(suite, coveredGoals, fitness);
updateIndividual(this, suite, fitness);
assert (coveredGoals <= totalGoals) : "Covered " + coveredGoals + " vs total goals " + totalGoals;
assert (fitness >= 0.0);
assert (fitness != 0.0 || coveredGoals == totalGoals) : "Fitness: " + fitness + ", " + "coverage: " + coveredGoals + "/" + totalGoals;
assert (suite.getCoverage(this) <= 1.0) && (suite.getCoverage(this) >= 0.0) : "Wrong coverage value " + suite.getCoverage(this);
return fitness;
}
Aggregations