/** * Builds the name map based on coverage goal stored as covered in each of the tests * @param tests * @return */ private Map<TestCase, Set<TestFitnessFunction>> initializeCoverageMapFromTests(List<TestCase> tests) { Map<TestCase, Set<TestFitnessFunction>> testToGoals = new LinkedHashMap<>(); for(TestCase test : tests) { testToGoals.put(test, filterSupportedGoals(new LinkedHashSet<>(test.getCoveredGoals()))); } return testToGoals; }
/** * Builds the name map based on coverage goals stored as covered in the tests pointed to by results * @param results * @return */ private Map<TestCase, Set<TestFitnessFunction>> initializeCoverageMapFromResults(List<ExecutionResult> results) { Map<TestCase, Set<TestFitnessFunction>> testToGoals = new LinkedHashMap<>(); for(ExecutionResult result : results) { testToGoals.put(result.test, filterSupportedGoals(new LinkedHashSet<>(result.test.getCoveredGoals()))); } return testToGoals; }
/** * <p> * getCoveredGoals * </p> * * @return a {@link java.util.Set} object. */ public Set<TestFitnessFunction> getCoveredGoals() { Set<TestFitnessFunction> goals = new LinkedHashSet<TestFitnessFunction>(); for (TestChromosome test : tests) { final Set<TestFitnessFunction> goalsForTest = test.getTestCase().getCoveredGoals(); goals.addAll(goalsForTest); } return goals; }
/** * Store the test cases that are optimal for the test goal in the archive * @param solution covering test case * @param covered covered branch */ private void updateArchive(T solution, FitnessFunction<T> covered) { // the next two lines are needed since that coverage information are used // during EvoSuite post-processing TestChromosome tch = (TestChromosome) solution; tch.getTestCase().getCoveredGoals().add((TestFitnessFunction) covered); if (!archive.containsKey(covered)){ archive.put(covered, solution); this.uncoveredBranches.remove(covered); } }
/** * There is nothing unique about the test, so we have to add goals until we find a unique name */ private Set<TestFitnessFunction> getUniqueNonMethodGoals(TestCase test, Map<TestCase, Set<TestFitnessFunction>> testToGoals) { Set<TestFitnessFunction> allGoals = new LinkedHashSet<>(); for (Set<TestFitnessFunction> goals : testToGoals.values()) { allGoals.addAll(goals); } Set<TestFitnessFunction> goals = new LinkedHashSet<>(); for(TestFitnessFunction goal : filterSupportedGoals(test.getCoveredGoals())) { if(goal instanceof MethodCoverageTestFitness) continue; if(goal instanceof MethodNoExceptionCoverageTestFitness) continue; if(!allGoals.contains(goal)) { goals.add(goal); } } return goals; }
private void resolveAmbiguity(Set<TestCase> tests) { // Full list of goals for given tests Map<TestCase, Set<TestFitnessFunction>> testToGoals = new LinkedHashMap<>(); for(TestCase test : tests) { testToGoals.put(test, filterSupportedGoals(new LinkedHashSet<>(test.getCoveredGoals()))); } // Find out what is unique about each one findUniqueGoals(testToGoals); }
/** * Create a map from coverage goal to tests that cover this goal * * @param goalMap * @param suite */ private void populateCoverageMap( Map<TestFitnessFunction, Set<TestChromosome>> goalMap, TestSuiteChromosome suite) { for (TestChromosome test : suite.getTestChromosomes()) { for (TestFitnessFunction goal : test.getTestCase().getCoveredGoals()) { if (!goalMap.containsKey(goal)) goalMap.put(goal, new HashSet<TestChromosome>()); goalMap.get(goal).add(test); } } }
private void writeCoveredGoalsFile() { if (Properties.WRITE_COVERED_GOALS_FILE) { StringBuilder builder = new StringBuilder(); File file = new File(Properties.COVERED_GOALS_FILE); for (int i = 0; i < testCases.size(); i++) { TestCase test = testCases.get(i); String generatedName = nameGenerator.getName(test); String testName = (generatedName != null) ? generatedName : TestSuiteWriterUtils.getNameOfTest(testCases, i); Set<TestFitnessFunction> coveredGoals = test.getCoveredGoals(); for (TestFitnessFunction goal : coveredGoals) { builder.append(testName + "," + goal.toString() + NEWLINE); } } FileIOUtils.writeFile(builder.toString(), file); } } }
tch.getTestCase().getCoveredGoals().add((TestFitnessFunction) f);
coveredGoals.addAll(test.getTestCase().getCoveredGoals()); finalTests.add(test);
Set<TestFitnessFunction> coveredGoals = test.getCoveredGoals();
Set<TestFitnessFunction> goals = filterSupportedGoals(new LinkedHashSet<>(test.getCoveredGoals()));
List<TestFitnessFunction> goals = new ArrayList<>(getUniqueNonMethodGoals(entry.getKey(), testToGoals)); if(goals.isEmpty()) { goals.addAll(filterSupportedGoals(entry.getKey().getCoveredGoals()));