private void chopException(TestCase test, ExecutionResult result) { if (!result.noThrownExceptions()) { // No code including or after an exception should be in the pool Integer pos = result.getFirstPositionOfThrownException(); if (pos != null) { test.chop(pos); } else { test.chop(test.size() - 1); } } }
/** * {@inheritDoc} */ @Override public void updateArchive(F target, T solution, double fitnessValue) { super.updateArchive(target, solution, fitnessValue); assert this.archive.containsKey(target); ExecutionResult executionResult = solution.getLastExecutionResult(); // remove all statements after an exception if (!executionResult.noThrownExceptions()) { solution.getTestCase().chop(executionResult.getFirstPositionOfThrownException() + 1); } boolean isNewCoveredTarget = this.archive.get(target) .addSolution(1.0 - FitnessFunction.normalize(fitnessValue), solution); if (isNewCoveredTarget) { this.removeNonCoveredTargetOfAMethod(target); this.hasBeenUpdated = true; } }
/** * <p> * Constructor for ContractViolation. * </p> * * @param contract * a {@link org.evosuite.contracts.Contract} object. * @param statement * a {@link org.evosuite.testcase.statements.Statement} object. * @param exception * a {@link java.lang.Throwable} object. */ public ContractViolation(Contract contract, Statement statement, Throwable exception, VariableReference... variables) { this.contract = contract; this.test = statement.getTestCase().clone(); this.test.chop(statement.getPosition() + 1); ((DefaultTestCase) this.test).setFailing(true); this.statement = this.test.getStatement(statement.getPosition()); for (VariableReference var : variables) { this.variables.add(var.clone(this.test)); } this.exception = exception; }
} else { test.getTestCase().chop(pos + 1);
test.chop(lastPosition + 1);
int position = result.getFirstPositionOfThrownException(); if (position > 0) { test.getTestCase().chop(position); result = TestCaseExecutor.runTest(test.getTestCase()); test.setLastExecutionResult(result);