use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testConstructorWithFullyQualifiedClassName.
@Test
public void testConstructorWithFullyQualifiedClassName() {
TestCase test = new DefaultTestCase();
MethodCoverageTestFitness goal = new MethodCoverageTestFitness("org.package.name.FooClass", "<init>()");
test.addCoveredGoal(goal);
List<TestCase> tests = new ArrayList<>();
tests.add(test);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
String generatedName = naming.getName(test);
assertEquals("testCreatesFooClass", generatedName);
}
use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testOverloadedMethod.
@Test
public void testOverloadedMethod() {
TestCase test1 = new DefaultTestCase();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "foo()");
test1.addCoveredGoal(goal1);
TestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 0));
MethodCoverageTestFitness goal2 = new MethodCoverageTestFitness("FooClass", "foo(I)");
test2.addCoveredGoal(goal2);
TestCase test3 = new DefaultTestCase();
// Need to add statements to change hashCode
test3.addStatement(new IntPrimitiveStatement(test3, 0));
MethodCoverageTestFitness goal3 = new MethodCoverageTestFitness("FooClass", "foo(II)");
test3.addCoveredGoal(goal3);
List<TestCase> tests = new ArrayList<>();
tests.add(test1);
tests.add(test2);
tests.add(test3);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
assertEquals("testFooTakingNoArguments", naming.getName(test1));
assertEquals("testFooTakingInt", naming.getName(test2));
assertEquals("testFooTaking2Arguments", naming.getName(test3));
}
use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testTwoUniqueMethods.
@Test
public void testTwoUniqueMethods() {
TestCase test = new DefaultTestCase();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "foo");
test.addCoveredGoal(goal1);
MethodCoverageTestFitness goal2 = new MethodCoverageTestFitness("FooClass", "bar");
test.addCoveredGoal(goal2);
List<TestCase> tests = new ArrayList<>();
tests.add(test);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
String generatedName = naming.getName(test);
assertEquals("testBarAndFoo", generatedName);
}
use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestGoalComparator method testComparatorList.
@Test
public void testComparatorList() {
GoalComparator comparator = new GoalComparator();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString()");
ExceptionCoverageTestFitness goal2 = new ExceptionCoverageTestFitness("FooClass", "toString()", MockArithmeticException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
OutputCoverageGoal outputGoal = new OutputCoverageGoal("FooClass", "toString", Type.getType("Ljava.lang.String;"), IOCoverageConstants.REF_NONNULL);
OutputCoverageTestFitness goal3 = new OutputCoverageTestFitness(outputGoal);
List<TestFitnessFunction> goals = new ArrayList<>();
goals.add(goal1);
goals.add(goal2);
goals.add(goal3);
Collections.sort(goals, comparator);
assertEquals(goal2, goals.get(0));
}
use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestGoalComparator method testCompareExceptionMethod.
@Test
public void testCompareExceptionMethod() {
GoalComparator comparator = new GoalComparator();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString()");
ExceptionCoverageTestFitness goal2 = new ExceptionCoverageTestFitness("FooClass", "toString()", MockArithmeticException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
assertEquals(1, comparator.compare(goal1, goal2));
}
Aggregations