use of org.evosuite.coverage.method.MethodNoExceptionCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testConstructorWithAndWithoutException.
@Test
public void testConstructorWithAndWithoutException() {
TestCase test1 = new DefaultTestCase();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "<init>()");
test1.addCoveredGoal(goal1);
MethodNoExceptionCoverageTestFitness goal1a = new MethodNoExceptionCoverageTestFitness("FooClass", "<init>()");
test1.addCoveredGoal(goal1a);
TestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 0));
test2.addCoveredGoal(goal1);
ExceptionCoverageTestFitness goal2 = new ExceptionCoverageTestFitness("FooClass", "<init>()", RuntimeException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
test2.addCoveredGoal(goal2);
List<TestCase> tests = new ArrayList<>();
tests.add(test1);
tests.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
assertEquals("testCreatesFooClass", naming.getName(test1));
assertEquals("testFailsToCreateFooClassThrowsRuntimeException", naming.getName(test2));
}
use of org.evosuite.coverage.method.MethodNoExceptionCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testResolveMethodNames.
@Test
public void testResolveMethodNames() {
MethodCoverageTestFitness methodGoal = new MethodCoverageTestFitness("org.apache.commons.scxml.Builtin", "isMember(Ljava/util/Set;Ljava/lang/String;)Z");
MethodNoExceptionCoverageTestFitness methodNoExGoal = new MethodNoExceptionCoverageTestFitness("org.apache.commons.scxml.Builtin", "isMember(Ljava/util/Set;Ljava/lang/String;)Z");
OutputCoverageGoal outputGoalHelper1 = new OutputCoverageGoal("org.apache.commons.scxml.Builtin", "isMember(Ljava/util/Set;Ljava/lang/String;)Z", Type.BOOLEAN_TYPE, BOOL_FALSE);
OutputCoverageTestFitness outputGoalFalse = new OutputCoverageTestFitness(outputGoalHelper1);
OutputCoverageGoal outputGoalHelper2 = new OutputCoverageGoal("org.apache.commons.scxml.Builtin", "isMember(Ljava/util/Set;Ljava/lang/String;)Z", Type.BOOLEAN_TYPE, BOOL_TRUE);
OutputCoverageTestFitness outputGoalTrue = new OutputCoverageTestFitness(outputGoalHelper2);
InputCoverageGoal inputGoalHelper1 = new InputCoverageGoal("org.apache.commons.scxml.Builtin", "isMember(Ljava/util/Set;Ljava/lang/String;)Z", 0, Type.getType(Set.class), SET_EMPTY);
InputCoverageTestFitness inputGoalEmptySet = new InputCoverageTestFitness(inputGoalHelper1);
InputCoverageGoal inputGoalHelper2 = new InputCoverageGoal("org.apache.commons.scxml.Builtin", "isMember(Ljava/util/Set;Ljava/lang/String;)Z", 0, Type.getType(Set.class), SET_NONEMPTY);
InputCoverageTestFitness inputGoalNonEmptySet = new InputCoverageTestFitness(inputGoalHelper2);
InputCoverageGoal inputGoalHelper3 = new InputCoverageGoal("org.apache.commons.scxml.Builtin", "isMember(Ljava/util/Set;Ljava/lang/String;)Z", 1, Type.getType(String.class), STRING_NONEMPTY);
InputCoverageTestFitness inputGoalStringNonEmpty = new InputCoverageTestFitness(inputGoalHelper3);
TestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(methodGoal);
test1.addCoveredGoal(methodNoExGoal);
test1.addCoveredGoal(inputGoalEmptySet);
test1.addCoveredGoal(inputGoalStringNonEmpty);
test1.addCoveredGoal(outputGoalFalse);
TestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 0));
test2.addCoveredGoal(methodGoal);
test2.addCoveredGoal(methodNoExGoal);
test2.addCoveredGoal(inputGoalNonEmptySet);
test2.addCoveredGoal(inputGoalStringNonEmpty);
test2.addCoveredGoal(outputGoalFalse);
TestCase test3 = new DefaultTestCase();
// Need to add statements to change hashCode
test3.addStatement(new IntPrimitiveStatement(test3, 1));
test3.addCoveredGoal(methodGoal);
test3.addCoveredGoal(methodNoExGoal);
test3.addCoveredGoal(inputGoalNonEmptySet);
test3.addCoveredGoal(inputGoalStringNonEmpty);
test3.addCoveredGoal(outputGoalTrue);
List<TestCase> tests = new ArrayList<>();
tests.add(test1);
tests.add(test2);
tests.add(test3);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
assertEquals("testIsMemberWithEmptySet", naming.getName(test1));
assertEquals("testIsMemberReturningFalse", naming.getName(test2));
assertEquals("testIsMemberReturningTrue", naming.getName(test3));
}
use of org.evosuite.coverage.method.MethodNoExceptionCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testMethodWithAndWithoutException.
@Test
public void testMethodWithAndWithoutException() {
TestCase test1 = new DefaultTestCase();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString()");
test1.addCoveredGoal(goal1);
MethodNoExceptionCoverageTestFitness goal1a = new MethodNoExceptionCoverageTestFitness("FooClass", "toString()");
test1.addCoveredGoal(goal1a);
TestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 0));
test2.addCoveredGoal(goal1);
ExceptionCoverageTestFitness goal2 = new ExceptionCoverageTestFitness("FooClass", "toString()", RuntimeException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
test2.addCoveredGoal(goal2);
List<TestCase> tests = new ArrayList<>();
tests.add(test1);
tests.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
assertEquals("testToString", naming.getName(test1));
assertEquals("testToStringThrowsRuntimeException", naming.getName(test2));
}
use of org.evosuite.coverage.method.MethodNoExceptionCoverageTestFitness 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.coverage.method.MethodNoExceptionCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testMethodWithAndWithoutMockException.
@Test
public void testMethodWithAndWithoutMockException() {
TestCase test1 = new DefaultTestCase();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString()");
test1.addCoveredGoal(goal1);
MethodNoExceptionCoverageTestFitness goal1a = new MethodNoExceptionCoverageTestFitness("FooClass", "toString()");
test1.addCoveredGoal(goal1a);
TestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 0));
test2.addCoveredGoal(goal1);
ExceptionCoverageTestFitness goal2 = new ExceptionCoverageTestFitness("FooClass", "toString()", MockArithmeticException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
test2.addCoveredGoal(goal2);
List<TestCase> tests = new ArrayList<>();
tests.add(test1);
tests.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
assertEquals("testToString", naming.getName(test1));
assertEquals("testToStringThrowsArithmeticException", naming.getName(test2));
}
Aggregations