use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class CoverageGoalTestNameGenerationStrategy method generateNames.
/**
* Helper method that does the bulk of the work
* @param testToGoals
*/
private void generateNames(Map<TestCase, Set<TestFitnessFunction>> testToGoals) {
initializeMethodCoverageCount(testToGoals);
findUniqueGoals(testToGoals);
initializeNameGoals(testToGoals);
// Iteratively add goals as long as there are resolvable ambiguities
boolean changed = true;
while (changed) {
setTestNames(testToGoals);
Map<String, Set<TestCase>> dupTestNameMap = determineDuplicateNames();
// For each duplicate set, add new test goals
changed = false;
for (Map.Entry<String, Set<TestCase>> entry : dupTestNameMap.entrySet()) {
if (entry.getKey().length() >= MAX_CHARS) {
continue;
}
// Try adding something unique for the given test set
if (resolveAmbiguity(testToGoals, entry.getValue(), true))
changed = true;
else {
// the number of tests in this ambiguity group
if (resolveAmbiguity(testToGoals, entry.getValue(), false))
changed = true;
}
}
}
// If there is absolutely nothing unique, add the top goals so that the test at least has a name
for (Map.Entry<TestCase, Set<TestFitnessFunction>> entry : testToGoals.entrySet()) {
if (entry.getValue().isEmpty()) {
List<TestFitnessFunction> goals = new ArrayList<>(getUniqueNonMethodGoals(entry.getKey(), testToGoals));
if (goals.isEmpty()) {
goals.addAll(filterSupportedGoals(entry.getKey().getCoveredGoals()));
}
Collections.sort(goals, new GoalComparator());
if (!goals.isEmpty()) {
TestFitnessFunction goal = goals.iterator().next();
entry.getValue().add(goal);
String name = getTestName(entry.getKey(), entry.getValue());
testToName.put(entry.getKey(), name);
}
}
}
// Add numbers to remaining duplicate names
fixAmbiguousTestNames();
}
use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class CoverageGoalTestNameGenerationStrategy method getUniqueNonMethodGoals.
/**
* 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;
}
use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class TestSuiteChromosome method getCoveredGoals.
/**
* <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;
}
use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class MockJOptionPaneShowInternalOptionDialogTest method testShowInternalInputDialogs.
@Test
public void testShowInternalInputDialogs() throws Exception {
TestSuiteChromosome suite = new TestSuiteChromosome();
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t1 = buildTestCase0(cl);
suite.addTest(t1);
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
Set<TestFitnessFunction> coveredGoals = suite.getCoveredGoals();
Assert.assertEquals(2, coveredGoals.size());
}
use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class MockJOptionPaneShowMessageDialogTest method testShowMessageDialog0.
@Test
public void testShowMessageDialog0() throws Exception {
TestSuiteChromosome suite = new TestSuiteChromosome();
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t0 = buildTestCase0TrueBranch(cl);
TestCase t1 = buildTestCase0FalseBranch(cl);
suite.addTest(t0);
suite.addTest(t1);
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
Set<TestFitnessFunction> coveredGoals = suite.getCoveredGoals();
Assert.assertEquals(3, coveredGoals.size());
}
Aggregations