use of org.evosuite.coverage.exception.ExceptionCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testConstructorExceptionWithFullyQualifiedClassName.
@Test
public void testConstructorExceptionWithFullyQualifiedClassName() {
TestCase test = new DefaultTestCase();
ExceptionCoverageTestFitness goal = new ExceptionCoverageTestFitness("org.package.name.FooClass", "<init>()", RuntimeException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
test.addCoveredGoal(goal);
List<TestCase> tests = new ArrayList<>();
tests.add(test);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
String generatedName = naming.getName(test);
assertEquals("testFailsToCreateFooClassThrowsRuntimeException", generatedName);
}
use of org.evosuite.coverage.exception.ExceptionCoverageTestFitness 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.exception.ExceptionCoverageTestFitness 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.coverage.exception.ExceptionCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testExceptionInOverloadedConstructor.
@Test
public void testExceptionInOverloadedConstructor() {
TestCase test1 = new DefaultTestCase();
ExceptionCoverageTestFitness goal1 = new ExceptionCoverageTestFitness(ClassWithOverloadedConstructor.class.getCanonicalName(), "<init>()", NullPointerException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
test1.addCoveredGoal(goal1);
TestCase test2 = new DefaultTestCase();
ExceptionCoverageTestFitness goal2 = new ExceptionCoverageTestFitness(ClassWithOverloadedConstructor.class.getCanonicalName(), "<init>(Ljava/lang/String;)", NullPointerException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 0));
test2.addCoveredGoal(goal2);
TestCase test3 = new DefaultTestCase();
ExceptionCoverageTestFitness goal3 = new ExceptionCoverageTestFitness(ClassWithOverloadedConstructor.class.getCanonicalName(), "<init>(II)", NullPointerException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
// 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);
assertEquals("testFailsToCreateClassWithOverloadedConstructorTakingNoArgumentsThrowsNullPointerException", generatedName1);
assertEquals("testFailsToCreateClassWithOverloadedConstructorTakingStringThrowsNullPointerException", generatedName2);
assertEquals("testFailsToCreateClassWithOverloadedConstructorTaking2ArgumentsThrowsNullPointerException", generatedName3);
}
use of org.evosuite.coverage.exception.ExceptionCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testMethodWithAndWithoutException.
@Test
public void testMethodWithAndWithoutException() {
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()", 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("testToString", naming.getName(test1));
assertEquals("testToStringThrowsRuntimeException", naming.getName(test2));
}
Aggregations