use of org.evosuite.coverage.exception.ExceptionCoverageTestFitness in project evosuite by EvoSuite.
the class TestGoalComparator method testCompareEqual.
@Test
public void testCompareEqual() {
GoalComparator comparator = new GoalComparator();
ExceptionCoverageTestFitness goal1 = new ExceptionCoverageTestFitness("FooClass", "toString()", MockArithmeticException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
ExceptionCoverageTestFitness goal2 = new ExceptionCoverageTestFitness("FooClass", "toString()", MockArithmeticException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
assertEquals(0, comparator.compare(goal1, goal2));
}
use of org.evosuite.coverage.exception.ExceptionCoverageTestFitness in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testIDNamingWithSameMethodGoals2.
@Test
public void testIDNamingWithSameMethodGoals2() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
// method goals
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>(LField;II)V");
TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "<init>(LFieldMatrix;)V");
// exception goals
TestFitnessFunction goal3 = new ExceptionCoverageTestFitness("FooClass", "<init>(LField;II)V", ArrayIndexOutOfBoundsException.class, ExceptionCoverageTestFitness.ExceptionType.IMPLICIT);
// input goals
TestFitnessFunction goal4 = new InputCoverageTestFitness(new InputCoverageGoal("FooClass", "<init>(LFieldMatrix;)V", 0, Type.getType("LFieldMatrix;"), REF_NULL));
TestFitnessFunction goal5 = new InputCoverageTestFitness(new InputCoverageGoal("FooClass", "<init>(LFieldMatrix;)V", 0, Type.getType("LFieldMatrix;"), REF_NONNULL));
TestFitnessFunction goal6 = new InputCoverageTestFitness(new InputCoverageGoal("FooClass", "<init>(LField;II)V", 0, Type.getType("LField;"), REF_NONNULL));
TestFitnessFunction goal7 = new InputCoverageTestFitness(new InputCoverageGoal("FooClass", "<init>(LField;II)V", 1, Type.INT_TYPE, NUM_ZERO));
TestFitnessFunction goal8 = new InputCoverageTestFitness(new InputCoverageGoal("FooClass", "<init>(LField;II)V", 1, Type.INT_TYPE, NUM_NEGATIVE));
TestFitnessFunction goal9 = new InputCoverageTestFitness(new InputCoverageGoal("FooClass", "<init>(LField;II)V", 2, Type.INT_TYPE, NUM_ZERO));
DefaultTestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(goal1);
test1.addCoveredGoal(goal3);
test1.addCoveredGoal(goal6);
// unique
test1.addCoveredGoal(goal7);
// unique
test1.addCoveredGoal(goal9);
DefaultTestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 2));
test2.addCoveredGoal(goal2);
test2.addCoveredGoal(goal3);
// unique
test2.addCoveredGoal(goal4);
DefaultTestCase test3 = new DefaultTestCase();
// Need to add statements to change hashCode
test3.addStatement(new IntPrimitiveStatement(test3, 3));
test3.addCoveredGoal(goal1);
test3.addCoveredGoal(goal2);
test3.addCoveredGoal(goal3);
// unique
test3.addCoveredGoal(goal5);
test3.addCoveredGoal(goal6);
// unique
test3.addCoveredGoal(goal8);
ArrayList<TestCase> testCases = new ArrayList<>();
testCases.add(test1);
testCases.add(test2);
testCases.add(test3);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(testCases);
String nameTest1 = naming.getName(test1);
String nameTest2 = naming.getName(test2);
String nameTest3 = naming.getName(test3);
assertEquals("Generated test name differs from expected", "testCreatesFooClassTaking3ArgumentsWithZeroAndZero", nameTest1);
assertEquals("Generated test name differs from expected", "testCreatesFooClassTakingFieldMatrixWithNull", nameTest2);
// TODO: Why is Positive vs nonnull nondeterministically chosen?
assertEquals("Generated test name differs from expected", "testCreatesFooClassTaking3ArgumentsWithNegative", nameTest3);
}
use of org.evosuite.coverage.exception.ExceptionCoverageTestFitness in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testConstructors.
@Test
public void testConstructors() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
// method goal
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>(LFooClass;)V");
// exception goal
TestFitnessFunction goal2 = new ExceptionCoverageTestFitness("FooClass", "<init>(LFooClass;)V", ArrayIndexOutOfBoundsException.class, ExceptionCoverageTestFitness.ExceptionType.IMPLICIT);
DefaultTestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(goal1);
DefaultTestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 2));
test2.addCoveredGoal(goal1);
test2.addCoveredGoal(goal2);
ArrayList<TestCase> testCases = new ArrayList<>();
testCases.add(test1);
testCases.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(testCases);
String nameTest1 = naming.getName(test1);
String nameTest2 = naming.getName(test2);
assertEquals("Generated test name differs from expected", "testCreatesFooClass", nameTest1);
assertEquals("Generated test name differs from expected", "testFailsToCreateFooClassThrowsArrayIndexOutOfBoundsException", nameTest2);
}
use of org.evosuite.coverage.exception.ExceptionCoverageTestFitness in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testMethodWithExceptions.
@Test
public void testMethodWithExceptions() {
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", "toString2()");
test2.addCoveredGoal(goal2);
ExceptionCoverageTestFitness goal3 = new ExceptionCoverageTestFitness("FooClass", "toString()", MockArithmeticException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
test1.addCoveredGoal(goal3);
test2.addCoveredGoal(goal3);
List<TestCase> tests = new ArrayList<>();
tests.add(test1);
tests.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
assertEquals("testToString", naming.getName(test1));
assertEquals("testToString2", naming.getName(test2));
}
use of org.evosuite.coverage.exception.ExceptionCoverageTestFitness 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));
}
Aggregations