use of org.evosuite.coverage.io.output.OutputCoverageGoal in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testNullOutputGoal.
@Test
public void testNullOutputGoal() {
TestCase test = new DefaultTestCase();
OutputCoverageGoal outputGoal1 = new OutputCoverageGoal("FooClass", "foo", Type.getType("Ljava.lang.Object;"), REF_NULL);
OutputCoverageTestFitness goal1 = new OutputCoverageTestFitness(outputGoal1);
test.addCoveredGoal(goal1);
List<TestCase> tests = new ArrayList<>();
tests.add(test);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
assertEquals("testFooReturningNull", naming.getName(test));
}
use of org.evosuite.coverage.io.output.OutputCoverageGoal in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testMultipleRedundantGoals.
@Test
public void testMultipleRedundantGoals() {
MethodCoverageTestFitness methodGoal1 = new MethodCoverageTestFitness("FooClass", "foo(SS)Z");
MethodCoverageTestFitness methodGoal2 = new MethodCoverageTestFitness("FooClass", "foo(Ljava/lang/Object;Ljava/lang/Object;)Z");
OutputCoverageTestFitness outputGoal1 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "foo(SS)Z", Type.BOOLEAN_TYPE, BOOL_FALSE));
OutputCoverageTestFitness outputGoal2 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "foo(Ljava/lang/Object;Ljava/lang/Object;)Z", Type.BOOLEAN_TYPE, BOOL_FALSE));
TestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(methodGoal1);
test1.addCoveredGoal(outputGoal1);
TestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 0));
test2.addCoveredGoal(methodGoal2);
test2.addCoveredGoal(outputGoal2);
List<TestCase> tests = new ArrayList<>();
tests.add(test1);
tests.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
assertEquals("testFooTaking2Shorts", naming.getName(test1));
assertEquals("testFooTaking2Objects", naming.getName(test2));
}
use of org.evosuite.coverage.io.output.OutputCoverageGoal 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.io.output.OutputCoverageGoal in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testThreeTestsOutputGoals.
@Test
public void testThreeTestsOutputGoals() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
// Method goals
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "mist(I)V");
TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "keys()");
// Output goals for method keys()I
TestFitnessFunction goal3 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "keys()", Type.INT_TYPE, NUM_POSITIVE));
TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "keys()", Type.INT_TYPE, NUM_NEGATIVE));
DefaultTestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(goal1);
DefaultTestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 2));
test2.addCoveredGoal(goal1);
test2.addCoveredGoal(goal2);
test2.addCoveredGoal(goal3);
DefaultTestCase test3 = new DefaultTestCase();
// Need to add statements to change hashCode
test3.addStatement(new IntPrimitiveStatement(test3, 3));
test3.addCoveredGoal(goal1);
test3.addCoveredGoal(goal2);
test3.addCoveredGoal(goal4);
ArrayList<TestCase> testCases = new ArrayList<>();
testCases.add(test1);
testCases.add(test2);
testCases.add(test3);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(testCases);
String nameTest1 = naming.getName(test1);
String nameTest2 = naming.getName(test2);
String nameTest3 = naming.getName(test3);
assertEquals("Generated test name differs from expected", "testMist", nameTest1);
assertEquals("Generated test name differs from expected", "testKeysReturningPositive", nameTest2);
assertEquals("Generated test name differs from expected", "testKeysReturningNegative", nameTest3);
}
use of org.evosuite.coverage.io.output.OutputCoverageGoal in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testTwoTestsOutputGoals.
@Test
public void testTwoTestsOutputGoals() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "keys()[I");
TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "<init>(LFooClass;)V");
TestFitnessFunction goal3 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "keys()", Type.INT_TYPE, NUM_NEGATIVE));
TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "keys()", Type.INT_TYPE, NUM_POSITIVE));
DefaultTestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(goal1);
test1.addCoveredGoal(goal2);
test1.addCoveredGoal(goal3);
DefaultTestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 2));
test2.addCoveredGoal(goal1);
test2.addCoveredGoal(goal2);
test2.addCoveredGoal(goal4);
ArrayList<TestCase> testCases = new ArrayList<>();
testCases.add(test1);
testCases.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(testCases);
String nameTest1 = naming.getName(test1);
String nameTest2 = naming.getName(test2);
// TODO: testKeysReturningNegative?
assertEquals("Generated test name differs from expected", "testKeysTakingNoArgumentsReturningNegative", nameTest1);
// TODO: testKeysReturningPositive?
assertEquals("Generated test name differs from expected", "testKeysTakingNoArgumentsReturningPositive", nameTest2);
}
Aggregations