use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testUniqueMethod.
@Test
public void testUniqueMethod() {
TestCase test = new DefaultTestCase();
MethodCoverageTestFitness goal = new MethodCoverageTestFitness("FooClass", "toString");
test.addCoveredGoal(goal);
List<TestCase> tests = new ArrayList<>();
tests.add(test);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
String generatedName = naming.getName(test);
assertEquals("testToString", generatedName);
}
use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testMethodWithInputOutputGoals.
@Test
public void testMethodWithInputOutputGoals() {
TestCase test1 = new DefaultTestCase();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString");
InputCoverageGoal inputGoal1 = new InputCoverageGoal("FooClass", "toString", 0, objectType(), REF_NULL);
InputCoverageTestFitness goal2 = new InputCoverageTestFitness(inputGoal1);
test1.addCoveredGoal(goal1);
test1.addCoveredGoal(goal2);
TestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 0));
test2.addCoveredGoal(goal1);
OutputCoverageGoal outputGoal2 = new OutputCoverageGoal("FooClass", "toString", objectType(), REF_NONNULL);
OutputCoverageTestFitness goal3 = new OutputCoverageTestFitness(outputGoal2);
test2.addCoveredGoal(goal3);
List<TestCase> tests = new ArrayList<>();
tests.add(test1);
tests.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
assertEquals("testToStringWithNull", naming.getName(test1));
assertEquals("testToStringReturningNonNull", naming.getName(test2));
}
use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testOverloadedConstructor.
@Test
public void testOverloadedConstructor() {
TestCase test1 = new DefaultTestCase();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness(ClassWithOverloadedConstructor.class.getCanonicalName(), "<init>()");
test1.addCoveredGoal(goal1);
TestCase test2 = new DefaultTestCase();
MethodCoverageTestFitness goal2 = new MethodCoverageTestFitness(ClassWithOverloadedConstructor.class.getCanonicalName(), "<init>(Ljava/lang/String;)");
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 0));
test2.addCoveredGoal(goal2);
TestCase test3 = new DefaultTestCase();
MethodCoverageTestFitness goal3 = new MethodCoverageTestFitness(ClassWithOverloadedConstructor.class.getCanonicalName(), "<init>(II)");
// Need to add statements to change hashCode
test3.addStatement(new IntPrimitiveStatement(test3, 1));
test3.addCoveredGoal(goal3);
List<TestCase> tests = new ArrayList<>();
tests.add(test1);
tests.add(test2);
tests.add(test3);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
String generatedName1 = naming.getName(test1);
String generatedName2 = naming.getName(test2);
String generatedName3 = naming.getName(test3);
// TODO: I would remove the WithOverloadedConstructor
assertEquals("testCreatesClassWithOverloadedConstructorTakingNoArguments", generatedName1);
assertEquals("testCreatesClassWithOverloadedConstructorTakingString", generatedName2);
assertEquals("testCreatesClassWithOverloadedConstructorTaking2Arguments", generatedName3);
}
use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testConstructorAndMethod.
@Test
public void testConstructorAndMethod() {
TestCase test = new DefaultTestCase();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("Foo", "<init>()");
test.addCoveredGoal(goal1);
MethodCoverageTestFitness goal2 = new MethodCoverageTestFitness("Foo", "bar()I");
test.addCoveredGoal(goal2);
List<TestCase> tests = new ArrayList<>();
tests.add(test);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
String generatedName = naming.getName(test);
assertEquals("testCreatesFooAndCallsBar", generatedName);
}
use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testResolveBasicConflict.
@Test
public void testResolveBasicConflict() {
// T1: A, B -> B
// T2: A, C -> C
// T3: A, C, B, D -> D
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();
MethodCoverageTestFitness methodGoal2 = new MethodCoverageTestFitness("FooClass", "toString()L/java/lang/String;");
test3.addCoveredGoal(methodGoal2);
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("testToString", naming.getName(test3));
}
Aggregations