use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testThreeTestsOutputGoals.
@Test
public void testThreeTestsOutputGoals() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
// Method goals
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "mist(I)V");
TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "keys()");
// Output goals for method keys()I
TestFitnessFunction goal3 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "keys()", Type.INT_TYPE, NUM_POSITIVE));
TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "keys()", Type.INT_TYPE, NUM_NEGATIVE));
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);
test2.addCoveredGoal(goal3);
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(goal4);
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", "testMist", nameTest1);
assertEquals("Generated test name differs from expected", "testKeysReturningPositive", nameTest2);
assertEquals("Generated test name differs from expected", "testKeysReturningNegative", nameTest3);
}
use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testTwoTestsOutputGoals.
@Test
public void testTwoTestsOutputGoals() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "keys()[I");
TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "<init>(LFooClass;)V");
TestFitnessFunction goal3 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "keys()", Type.INT_TYPE, NUM_NEGATIVE));
TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "keys()", Type.INT_TYPE, NUM_POSITIVE));
DefaultTestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(goal1);
test1.addCoveredGoal(goal2);
test1.addCoveredGoal(goal3);
DefaultTestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 2));
test2.addCoveredGoal(goal1);
test2.addCoveredGoal(goal2);
test2.addCoveredGoal(goal4);
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);
// TODO: testKeysReturningNegative?
assertEquals("Generated test name differs from expected", "testKeysTakingNoArgumentsReturningNegative", nameTest1);
// TODO: testKeysReturningPositive?
assertEquals("Generated test name differs from expected", "testKeysTakingNoArgumentsReturningPositive", nameTest2);
}
use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testConstructorAndOverloadedMethods.
@Test
public void testConstructorAndOverloadedMethods() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
// method goal
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>(LFooClass;)V");
TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "values()[B");
TestFitnessFunction goal3 = new MethodCoverageTestFitness("FooClass", "values([B)[B");
// exception goal
TestFitnessFunction goal4 = new ExceptionCoverageTestFitness("FooClass", "<init>(LFooClass;)V", ArrayIndexOutOfBoundsException.class, ExceptionCoverageTestFitness.ExceptionType.IMPLICIT);
// output goals
TestFitnessFunction goal5 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values()", Type.getType("[B"), ARRAY_NONEMPTY));
TestFitnessFunction goal6 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values([B)", Type.getType("[B"), ARRAY_EMPTY));
DefaultTestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(goal1);
test1.addCoveredGoal(goal2);
test1.addCoveredGoal(goal3);
test1.addCoveredGoal(goal5);
test1.addCoveredGoal(goal6);
DefaultTestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 2));
test2.addCoveredGoal(goal1);
test2.addCoveredGoal(goal2);
test2.addCoveredGoal(goal3);
test2.addCoveredGoal(goal4);
test2.addCoveredGoal(goal5);
test2.addCoveredGoal(goal6);
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", "testValuesTakingNoArgumentsReturningNonEmptyArray", nameTest1);
assertEquals("Generated test name differs from expected", "testFailsToCreateFooClassThrowsArrayIndexOutOfBoundsException", nameTest2);
}
Aggregations