use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testTwoTestsUniqueMethods.
@Test
public void testTwoTestsUniqueMethods() {
TestCase test1 = new DefaultTestCase();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString");
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", "getSomeStuff");
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("testGetSomeStuff", naming.getName(test2));
}
use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testResolveConflict2.
@Test
public void testResolveConflict2() {
// T1: A, B -> B
// T2: A, C -> C
// T3: A, B, C -> B & C
TestCase test1 = new DefaultTestCase();
MethodCoverageTestFitness methodGoal = new MethodCoverageTestFitness("FooClass", "foo(I)I");
test1.addCoveredGoal(methodGoal);
OutputCoverageGoal outputGoalHelper = new OutputCoverageGoal("FooClass", "foo(I)I", Type.INT_TYPE, NUM_ZERO);
OutputCoverageTestFitness outputGoal1 = new OutputCoverageTestFitness(outputGoalHelper);
test1.addCoveredGoal(outputGoal1);
TestCase test2 = new DefaultTestCase();
test2.addCoveredGoal(methodGoal);
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 0));
InputCoverageGoal inputGoalHelper = new InputCoverageGoal("FooClass", "foo(I)I", 0, Type.INT_TYPE, NUM_POSITIVE);
InputCoverageTestFitness inputGoal1 = new InputCoverageTestFitness(inputGoalHelper);
test2.addCoveredGoal(inputGoal1);
TestCase test3 = new DefaultTestCase();
test3.addCoveredGoal(methodGoal);
// Need to add statements to change hashCode
test3.addStatement(new IntPrimitiveStatement(test3, 1));
test3.addCoveredGoal(outputGoal1);
test3.addCoveredGoal(inputGoal1);
List<TestCase> tests = new ArrayList<>();
tests.add(test1);
tests.add(test2);
tests.add(test3);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
assertEquals("testFooReturningZero", naming.getName(test1));
assertEquals("testFooWithPositive", naming.getName(test2));
assertEquals("testFooReturningZeroAndFooWithPositive", naming.getName(test3));
}
use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testTwoMethodsOneWithException.
@Test
public void testTwoMethodsOneWithException() {
TestCase test = new DefaultTestCase();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "foo");
test.addCoveredGoal(goal1);
MethodCoverageTestFitness goal2 = new MethodCoverageTestFitness("FooClass", "bar");
test.addCoveredGoal(goal2);
ExceptionCoverageTestFitness goal3 = new ExceptionCoverageTestFitness("FooClass", "bar", RuntimeException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
test.addCoveredGoal(goal3);
List<TestCase> tests = new ArrayList<>();
tests.add(test);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
String generatedName = naming.getName(test);
assertEquals("testBarThrowsRuntimeException", generatedName);
}
use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testTwoUniqueMethodsWithLongNames.
@Test
public void testTwoUniqueMethodsWithLongNames() {
TestCase test = new DefaultTestCase();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "loremIpsumDolorSitAmetConsectetuerAdipiscingElit()V");
test.addCoveredGoal(goal1);
MethodCoverageTestFitness goal2 = new MethodCoverageTestFitness("FooClass", "sedDiamNonummNibhEuismodTinciduntUtLaoreetDoloreMagnaAliquamEratVolutpat()V");
test.addCoveredGoal(goal2);
List<TestCase> tests = new ArrayList<>();
tests.add(test);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
String generatedName = naming.getName(test);
assertEquals("testLoremIpsumDolorSitAmetConsectetuerAdipiscingElit", generatedName);
}
use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testResolveConflictWithTwoMethods.
@Test
public void testResolveConflictWithTwoMethods() {
// T1: A, B
// T2: A, C
// T3: A, B, C
TestCase test1 = new DefaultTestCase();
MethodCoverageTestFitness methodGoal = new MethodCoverageTestFitness("FooClass", "foo(I)I");
test1.addCoveredGoal(methodGoal);
OutputCoverageGoal outputGoalHelper = new OutputCoverageGoal("FooClass", "foo(I)I", Type.INT_TYPE, NUM_ZERO);
OutputCoverageTestFitness outputGoal1 = new OutputCoverageTestFitness(outputGoalHelper);
test1.addCoveredGoal(outputGoal1);
TestCase test2 = new DefaultTestCase();
test2.addCoveredGoal(methodGoal);
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 0));
InputCoverageGoal inputGoalHelper = new InputCoverageGoal("FooClass", "foo(I)I", 0, Type.INT_TYPE, NUM_POSITIVE);
InputCoverageTestFitness inputGoal1 = new InputCoverageTestFitness(inputGoalHelper);
test2.addCoveredGoal(inputGoal1);
TestCase test3 = new DefaultTestCase();
test3.addCoveredGoal(methodGoal);
// Need to add statements to change hashCode
test3.addStatement(new IntPrimitiveStatement(test3, 1));
test3.addCoveredGoal(outputGoal1);
test3.addCoveredGoal(inputGoal1);
List<TestCase> tests = new ArrayList<>();
tests.add(test1);
tests.add(test2);
tests.add(test3);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
assertEquals("testFooReturningZero", naming.getName(test1));
assertEquals("testFooWithPositive", naming.getName(test2));
assertEquals("testFooReturningZeroAndFooWithPositive", naming.getName(test3));
}
Aggregations