use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testMethodWithOutputGoals.
@Test
public void testMethodWithOutputGoals() {
TestCase test1 = new DefaultTestCase();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString");
OutputCoverageGoal outputGoal1 = new OutputCoverageGoal("FooClass", "toString", objectType(), REF_NULL);
OutputCoverageTestFitness goal2 = new OutputCoverageTestFitness(outputGoal1);
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("testToStringReturningNull", naming.getName(test1));
assertEquals("testToStringReturningNonNull", naming.getName(test2));
}
use of org.evosuite.testcase.DefaultTestCase 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.testcase.DefaultTestCase in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testOverloadedMethodWithObject.
@Test
public void testOverloadedMethodWithObject() {
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(Ljava/util/List;)");
test2.addCoveredGoal(goal2);
List<TestCase> tests = new ArrayList<>();
tests.add(test1);
tests.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
assertEquals("testFooTakingNoArguments", naming.getName(test1));
assertEquals("testFooTakingList", naming.getName(test2));
}
use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testMultipleMethods.
@Test
public void testMultipleMethods() throws NoSuchMethodException {
TestCase test = new DefaultTestCase();
GenericConstructor gc = new GenericConstructor(Object.class.getConstructor(), Object.class);
VariableReference callee = test.addStatement(new ConstructorStatement(test, gc, new ArrayList<VariableReference>()));
GenericMethod gm = new GenericMethod(Object.class.getMethod("toString"), Object.class);
test.addStatement(new MethodStatement(test, gm, callee, new ArrayList<VariableReference>()));
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString()Ljava/lang/String;");
test.addCoveredGoal(goal1);
MethodCoverageTestFitness goal2 = new MethodCoverageTestFitness("FooClass", "foo()Ljava/lang/String;");
test.addCoveredGoal(goal2);
MethodCoverageTestFitness goal3 = new MethodCoverageTestFitness("FooClass", "bar()Ljava/lang/String;");
test.addCoveredGoal(goal3);
List<TestCase> tests = new ArrayList<>();
tests.add(test);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
String generatedName = naming.getName(test);
assertEquals("testToString", generatedName);
// TODO: What should be the name now? Need some heuristic, currently sorted alphabetically
// Better heuristic would consider other things, like e.g. which method has more goals covered
// or which one is the last one called?
}
use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testOverloadedMethodDifferentArgArrayType.
@Test
public void testOverloadedMethodDifferentArgArrayType() {
TestCase test1 = new DefaultTestCase();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "foo([B)");
test1.addCoveredGoal(goal1);
OutputCoverageTestFitness outputGoal = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "foo", stringType(), BOOL_FALSE));
test1.addCoveredGoal(outputGoal);
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);
test2.addCoveredGoal(outputGoal);
List<TestCase> tests = new ArrayList<>();
tests.add(test1);
tests.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
assertEquals("testFooTakingByteArray", naming.getName(test1));
assertEquals("testFooTakingIntArray", naming.getName(test2));
}
Aggregations