/** * <p> * hasException * </p> * * @return a boolean. */ public boolean hasException() { return lastExecutionResult == null ? false : !lastExecutionResult.noThrownExceptions(); }
accessedClasses.addAll(result.test.getAccessedClasses()); if(!hasException) hasException = !result.noThrownExceptions();
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); } } }
private void removeAssertionsAfterException(List<ExecutionResult> results) { for(ExecutionResult result : results) { if(result.noThrownExceptions()) continue; int exceptionPosition = result.getFirstPositionOfThrownException(); // TODO: Not clear how that can happen... if(result.test.size() > exceptionPosition) result.test.getStatement(exceptionPosition).removeAssertions(); } }
/** * {@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; } }
private int getLastMutatableStatement() { ExecutionResult result = getLastExecutionResult(); if (result != null && !result.noThrownExceptions()) { int pos = result.getFirstPositionOfThrownException(); // It may happen that pos > size() after statements have been deleted if (pos >= test.size()) return test.size() - 1; else return pos; } else { return test.size() - 1; } }
continue; if (executionResult.noThrownExceptions()) { logger.info("Adding carved test without exception"); logger.info(test.toCode());
|| result.noThrownExceptions()) return;
if (result.hasTimeout() || result.hasTestException() || result.noThrownExceptions() || result.calledReflection()) { continue;
if (!resultA.noThrownExceptions() || !resultB.noThrownExceptions()) { double exDiff = RegressionExceptionHelper .compareExceptionDiffs(exceptionMapA, exceptionMapB);
if (!result.noThrownExceptions()) { num = result.getFirstPositionOfThrownException();
/** {@inheritDoc} */ public static ExecutionResult runTest(TestCase test, Mutation mutant) { ExecutionResult result = new ExecutionResult(test, mutant); try { if (mutant != null) logger.debug("Executing test for mutant " + mutant.getId() + ": \n" + test.toCode()); else logger.debug("Executing test without mutant"); if (mutant != null) MutationObserver.activateMutation(mutant); result = TestCaseExecutor.getInstance().execute(test); if (mutant != null) MutationObserver.deactivateMutation(mutant); int num = test.size(); if (!result.noThrownExceptions()) { num = result.getFirstPositionOfThrownException(); } //if (mutant == null) MaxStatementsStoppingCondition.statementsExecuted(num); int i = 0; for (AssertionTraceObserver<?> observer : observers) { result.setTrace(observer.getTrace(), observerClasses[i++]); } } catch (Exception e) { throw new Error(e); } return result; }
Map<String, Integer> callCount) { if (result.hasTimeout() || result.hasTestException() || result.noThrownExceptions()) { return;
/** * Execute a test case * * @param testChromosome The test case to execute * @return Result of the execution */ public ExecutionResult runTest(TestChromosome testChromosome) { if (testChromosome.getLastExecutionResult() != null && !testChromosome.isChanged()) { return testChromosome.getLastExecutionResult(); } TestCase test = testChromosome.getTestCase(); ExecutionResult result = new ExecutionResult(test, null); try { result = TestCaseExecutor.getInstance().execute(test); int num = test.size(); if (!result.noThrownExceptions()) { num = result.getFirstPositionOfThrownException(); } MaxStatementsStoppingCondition.statementsExecuted(num); // for(TestObserver observer : observers) { // observer.testResult(result); // } } catch (Exception e) { logger.error("TG: Exception caught: ", e); throw new RuntimeException(e); } return result; }
/** * If there is an exception in a superconstructor, then the corresponding * constructor might not be included in the execution trace * * @param results * @param callCount */ private static boolean hasConstructorException(ExecutionResult result, String className, String methodName) { if (result.hasTimeout() || result.hasTestException() || result.noThrownExceptions()) return false; Integer exceptionPosition = result.getFirstPositionOfThrownException(); if(!result.test.hasStatement(exceptionPosition)){ return false; } Statement statement = result.test.getStatement(exceptionPosition); if (statement instanceof ConstructorStatement) { ConstructorStatement c = (ConstructorStatement) statement; String constructorClassName = c.getConstructor().getName(); String constructorMethodName = "<init>" + Type.getConstructorDescriptor(c.getConstructor().getConstructor()); if(constructorClassName.equals(className) && constructorMethodName.equals(methodName)) { return true; } } return false; }
if (!result.noThrownExceptions()) { int idx = result.getFirstPositionOfThrownException(); logger.info("Exception thrown: " + result.getExceptionThrownAtPosition(idx));
@Override public boolean isCovered(TestChromosome individual, ExecutionResult result) { boolean covered = false; if (individual.getLastExecutionResult(mutation) == null) { covered = getFitness(individual, result) == 0.0; } if (!covered && individual.getLastExecutionResult(mutation) != null) { MutationExecutionResult mutantResult = individual.getLastExecutionResult(mutation); if (mutantResult.hasTimeout()) { covered = true; } else if (mutantResult.hasException() && result.noThrownExceptions()) { covered = true; } else if (mutantResult.getNumAssertions() > 0) { covered = true; } } return covered; } }
private MutationExecutionResult getMutationResult(ExecutionResult originalResult, ExecutionResult mutationResult) { MutationExecutionResult result = new MutationExecutionResult(); if (TestCoverageGoal.hasTimeout(mutationResult)) { logger.debug("Found timeout in mutant!"); MutationTimeoutStoppingCondition.timeOut(mutation); result.setHasTimeout(true); } if (mutationResult.noThrownExceptions()) { result.setHasException(true); } int numAssertions = getNumAssertions(originalResult, mutationResult); result.setNumAssertions(numAssertions); if (numAssertions == 0) { double impact = getSumDistance(originalResult.getTrace(), mutationResult.getTrace()); result.setImpact(impact); } return result; }
} else if (!mutantResult.noThrownExceptions() && origResult.noThrownExceptions()) { logger.debug("Increasing exception count."); if (!exceptionMutations.containsKey(m)) { || (!mutantResult.noThrownExceptions() && origResult.noThrownExceptions())) { killed.add(m.getId()); if (!origResult.noThrownExceptions()) { if (!test.getStatement(test.size() - 1).getAssertions().isEmpty()) { logger.debug("Removing assertions after exception");
if(result.noThrownExceptions()) { fitness = 0.0; // Exception difference exceptionCase = true;