/** * <p> * isCovered * </p> * * @param individual * a {@link org.evosuite.testcase.TestChromosome} object. * @param result * a {@link org.evosuite.testcase.execution.ExecutionResult} object. * @return a boolean. */ public boolean isCovered(TestChromosome individual, ExecutionResult result) { boolean covered = getFitness(individual, result) == 0.0; if (covered) { individual.test.addCoveredGoal(this); } return covered; }
/** * Executes the TestFitnessFunction.getFitness() function on the given * ExecutionResult but using the given targetTrace * * The ExecutionResult is left in it's original state after execution */ private double callTestFitnessFunctionForTrace(ExecutionTrace targetTrace, TestFitnessFunction targetFitness) { ExecutionTrace originalTrace = result.getTrace(); result.setTrace(targetTrace); double fitness = targetFitness.getFitness(individual, result); result.setTrace(originalTrace); return fitness; }
/** {@inheritDoc} */ @Override public double getFitness(TestChromosome individual, ExecutionResult result) { boolean archive = Properties.TEST_ARCHIVE; Properties.TEST_ARCHIVE = false; double defFitness = goalDefinitionFitness.getFitness(individual, result); if (defFitness == 0.0) { individual.getTestCase().removeCoveredGoal(goalDefinitionFitness); } Properties.TEST_ARCHIVE = archive; if (defFitness > 0) return 1 + normalize(defFitness); // TODO: filter all objects // TODO: compute minimum over all use-fitnesses // TODO: return that minimum after normalization, stop once a use-fitness is 0 // first inefficient version: double min = Double.MAX_VALUE; for (Use use : uses.keySet()) { double useFitness = uses.get(use).getFitness(individual, result); if (useFitness == 0) return 0; if (useFitness < min) min = useFitness; } return min; }
/** * Iterate over all execution results and summarize statistics * * @param results * @param coveredLines * @return */ private boolean analyzeTraces(List<ExecutionResult> results, Set<Integer> coveredLines) { boolean hasTimeoutOrTestException = false; for (ExecutionResult result : results) { if (result.hasTimeout() || result.hasTestException()) { hasTimeoutOrTestException = true; continue; } TestChromosome test = new TestChromosome(); test.setTestCase(result.test); test.setLastExecutionResult(result); test.setChanged(false); for (Integer goalID : this.lineGoals.keySet()) { TestFitnessFunction goal = this.lineGoals.get(goalID); double fit = goal.getFitness(test, result); // archive is updated by the TestFitnessFunction class if (fit == 0.0) { coveredLines.add(goalID); // helper to count the number of covered goals this.toRemoveLines.add(goalID); // goal to not be considered by the next iteration of the evolutionary algorithm } } } return hasTimeoutOrTestException; }
/** * Iterate over all execution results and summarize statistics * * @param results * @param coveredLines * @return */ private boolean analyzeTraces(List<ExecutionResult> results, Set<Integer> coveredLines) { boolean hasTimeoutOrTestException = false; for (ExecutionResult result : results) { if (result.hasTimeout() || result.hasTestException()) { hasTimeoutOrTestException = true; continue; } TestChromosome test = new TestChromosome(); test.setTestCase(result.test); test.setLastExecutionResult(result); test.setChanged(false); for (Integer goalID : this.lineGoals.keySet()) { TestFitnessFunction goal = this.lineGoals.get(goalID); double fit = goal.getFitness(test, result); // archive is updated by the TestFitnessFunction class if (fit == 0.0) { coveredLines.add(goalID); // helper to count the number of covered goals this.toRemoveLines.add(goalID); // goal to not be considered by the next iteration of the evolutionary algorithm } } } return hasTimeoutOrTestException; }
TestChromosome tc = new TestChromosome(); tc.setTestCase(result.test); double resultFitness = goal.getFitness(tc, result); if (resultFitness < goalFitness) goalFitness = resultFitness;
/** {@inheritDoc} */ @Override public double getFitness(TestChromosome individual) { logger.trace("Executing test case on original"); ExecutionResult origResult = individual.getLastExecutionResult(); if (origResult == null || individual.isChanged()) { origResult = runTest(individual.test); individual.setLastExecutionResult(origResult); individual.setChanged(false); } double fitness = getFitness(individual, origResult); updateIndividual(this, individual, fitness); return fitness; }
TestFitnessFunction goal = this.methodCoverageMap.get(methodName); double fit = goal.getFitness(test, result); // archive is updated by the TestFitnessFunction class
/** * Iterate over all execution results and summarise statistics. * * @param results * @param coveredStatements * @return */ private boolean analyzeTraces(List<ExecutionResult> results, Set<TestFitnessFunction> coveredStatements) { boolean hasTimeoutOrTestException = false; for (ExecutionResult result : results) { if (result.hasTimeout() || result.hasTestException()) { hasTimeoutOrTestException = true; continue; } TestChromosome test = new TestChromosome(); test.setTestCase(result.test); test.setLastExecutionResult(result); test.setChanged(false); for (TestFitnessFunction goal : this.statementGoals) { double fit = goal.getFitness(test, result); // archive is updated by the TestFitnessFunction class if (fit == 0.0) { coveredStatements.add(goal); // helper to count the number of covered goals this.toRemoveStatements.add(goal); // goal to not be considered by the next iteration of the evolutionary algorithm } } } return hasTimeoutOrTestException; }
double fitness = fitnessFunction.getFitness(c); if (isTimeoutReached()) { return; fitnessFunction.getFitness(c) >= fitness : fitnessFunction.getFitness(c) <= fitness) " to "+fitnessFunction.getFitness(c)+" on test "+c.getTestCase().toCode();
fit = goal.getFitness(test, result); // archive is updated by the TestFitnessFunction class
fit = goal.getFitness(test, result); // archive is updated by the TestFitnessFunction class
/** * Determines the BranchCoverageTestFitness of goalUseBranch considering the * full ExecutionTrace * * Is called on every call to getDistance() if the goalDefinition isn't * special s. isSpecialGoalDefinition() */ private double calculateUseFitnessForCompleteTrace() { // check ExecutionTrace.passedUses first, because calculating // BranchTestFitness takes time if (hasEntriesForId(result.getTrace().getPassedUses(goalUse.getVariableName()), goalUse.getUseId())) return 0.0; // return calculated fitness double fitness = goalUseFitness.getFitness(individual, result); // check for false positive: TODO warn? // this can happen, when a du is within a catch-block, since we // currently don't handle these correctly in the CDG department if (fitness == 0.0) return 1.0; return normalize(fitness); }
/** * Determines the BranchCoverageTestFitness of goalDefinitionBranch * considering the full ExecutionTrace * * Is called on every call to getDistance() if the goalDefinition isn't * special s. isSpecialGoalDefinition() */ private double calculateDefFitnessForCompleteTrace() { if (isSpecialDefinition(goalDefinition)) return 0.0; // check ExecutionTrace.passedDefinitions first, because calculating // BranchTestFitness takes time if (hasEntriesForId(result.getTrace().getPassedDefinitions(goalDefinition.getVariableName()), goalDefinition.getDefId())) return 0.0; // return calculated fitness double fitness = goalDefinitionFitness.getFitness(individual, result); // check for false positive: TODO warn? // this can happen, when a du is within a catch-block, since we // currently don't handle these correctly in the CDG department if (fitness == 0.0) return 1.0; return normalize(fitness); }
@Override public boolean isNotWorse() { ExecutionResult lastResult = individual.getLastExecutionResult(); individual.setChanged(true); individual.getTestCase().clearCoveredGoals(); double newFitness = fitness.getFitness(individual); boolean worse = false; if(fitness.isMaximizationFunction()) { if (newFitness < lastFitness) worse = true; } else { if (newFitness > lastFitness) worse = true; } if (!worse) { lastFitness = newFitness; individual.setFitness(fitness, lastFitness); return true; } else { individual.setFitness(fitness, lastFitness); individual.setLastExecutionResult(lastResult); return false; } } }