use of org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testMethodWithAndWithoutMockException.
@Test
public void testMethodWithAndWithoutMockException() {
TestCase test1 = new DefaultTestCase();
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString()");
test1.addCoveredGoal(goal1);
MethodNoExceptionCoverageTestFitness goal1a = new MethodNoExceptionCoverageTestFitness("FooClass", "toString()");
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", "toString()", MockArithmeticException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
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("testToStringThrowsArithmeticException", naming.getName(test2));
}
use of org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy 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.junit.naming.methods.CoverageGoalTestNameGenerationStrategy 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.junit.naming.methods.CoverageGoalTestNameGenerationStrategy in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testTwoTestsTwoMethodsOneWithException.
@Test
public void testTwoTestsTwoMethodsOneWithException() {
TestCase test1 = new DefaultTestCase();
TestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 0));
MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "foo");
test1.addCoveredGoal(goal1);
test2.addCoveredGoal(goal1);
MethodCoverageTestFitness goal2 = new MethodCoverageTestFitness("FooClass", "bar()I");
test1.addCoveredGoal(goal2);
test2.addCoveredGoal(goal2);
ExceptionCoverageTestFitness goal3 = new ExceptionCoverageTestFitness("FooClass", "bar()I", RuntimeException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
test1.addCoveredGoal(goal3);
MethodNoExceptionCoverageTestFitness goal4 = new MethodNoExceptionCoverageTestFitness("FooClass", "bar()I");
test2.addCoveredGoal(goal4);
List<TestCase> tests = new ArrayList<>();
tests.add(test1);
tests.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
String generatedName1 = naming.getName(test1);
String generatedName2 = naming.getName(test2);
assertEquals("testBarThrowsRuntimeException", generatedName1);
assertEquals("testBar", generatedName2);
}
use of org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy 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);
}
Aggregations