Search in sources :

Example 21 with OutputCoverageTestFitness

use of org.evosuite.coverage.io.output.OutputCoverageTestFitness 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));
}
Also used : TestCase(org.evosuite.testcase.TestCase) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) CoverageGoalTestNameGenerationStrategy(org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy) ArrayList(java.util.ArrayList) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) OutputCoverageTestFitness(org.evosuite.coverage.io.output.OutputCoverageTestFitness) OutputCoverageGoal(org.evosuite.coverage.io.output.OutputCoverageGoal) Test(org.junit.Test)

Example 22 with OutputCoverageTestFitness

use of org.evosuite.coverage.io.output.OutputCoverageTestFitness 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));
}
Also used : TestCase(org.evosuite.testcase.TestCase) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) MethodCoverageTestFitness(org.evosuite.coverage.method.MethodCoverageTestFitness) CoverageGoalTestNameGenerationStrategy(org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy) ArrayList(java.util.ArrayList) OutputCoverageTestFitness(org.evosuite.coverage.io.output.OutputCoverageTestFitness) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) OutputCoverageGoal(org.evosuite.coverage.io.output.OutputCoverageGoal) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Example 23 with OutputCoverageTestFitness

use of org.evosuite.coverage.io.output.OutputCoverageTestFitness in project evosuite by EvoSuite.

the class TestGoalComparator method testComparatorList.

@Test
public void testComparatorList() {
    GoalComparator comparator = new GoalComparator();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString()");
    ExceptionCoverageTestFitness goal2 = new ExceptionCoverageTestFitness("FooClass", "toString()", MockArithmeticException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
    OutputCoverageGoal outputGoal = new OutputCoverageGoal("FooClass", "toString", Type.getType("Ljava.lang.String;"), IOCoverageConstants.REF_NONNULL);
    OutputCoverageTestFitness goal3 = new OutputCoverageTestFitness(outputGoal);
    List<TestFitnessFunction> goals = new ArrayList<>();
    goals.add(goal1);
    goals.add(goal2);
    goals.add(goal3);
    Collections.sort(goals, comparator);
    assertEquals(goal2, goals.get(0));
}
Also used : ExceptionCoverageTestFitness(org.evosuite.coverage.exception.ExceptionCoverageTestFitness) MethodCoverageTestFitness(org.evosuite.coverage.method.MethodCoverageTestFitness) TestFitnessFunction(org.evosuite.testcase.TestFitnessFunction) ArrayList(java.util.ArrayList) OutputCoverageTestFitness(org.evosuite.coverage.io.output.OutputCoverageTestFitness) OutputCoverageGoal(org.evosuite.coverage.io.output.OutputCoverageGoal) GoalComparator(org.evosuite.junit.naming.methods.GoalComparator) Test(org.junit.Test)

Example 24 with OutputCoverageTestFitness

use of org.evosuite.coverage.io.output.OutputCoverageTestFitness 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);
}
Also used : DefaultTestCase(org.evosuite.testcase.DefaultTestCase) TestCase(org.evosuite.testcase.TestCase) TestFitnessFunction(org.evosuite.testcase.TestFitnessFunction) MethodCoverageTestFitness(org.evosuite.coverage.method.MethodCoverageTestFitness) ArrayList(java.util.ArrayList) OutputCoverageTestFitness(org.evosuite.coverage.io.output.OutputCoverageTestFitness) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) OutputCoverageGoal(org.evosuite.coverage.io.output.OutputCoverageGoal) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Example 25 with OutputCoverageTestFitness

use of org.evosuite.coverage.io.output.OutputCoverageTestFitness 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);
}
Also used : DefaultTestCase(org.evosuite.testcase.DefaultTestCase) TestCase(org.evosuite.testcase.TestCase) TestFitnessFunction(org.evosuite.testcase.TestFitnessFunction) MethodCoverageTestFitness(org.evosuite.coverage.method.MethodCoverageTestFitness) ArrayList(java.util.ArrayList) OutputCoverageTestFitness(org.evosuite.coverage.io.output.OutputCoverageTestFitness) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) OutputCoverageGoal(org.evosuite.coverage.io.output.OutputCoverageGoal) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)26 OutputCoverageGoal (org.evosuite.coverage.io.output.OutputCoverageGoal)26 OutputCoverageTestFitness (org.evosuite.coverage.io.output.OutputCoverageTestFitness)26 Test (org.junit.Test)26 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)25 TestCase (org.evosuite.testcase.TestCase)25 MethodCoverageTestFitness (org.evosuite.coverage.method.MethodCoverageTestFitness)18 CoverageGoalTestNameGenerationStrategy (org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy)18 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)17 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)8 InputCoverageGoal (org.evosuite.coverage.io.input.InputCoverageGoal)7 InputCoverageTestFitness (org.evosuite.coverage.io.input.InputCoverageTestFitness)7 ExceptionCoverageTestFitness (org.evosuite.coverage.exception.ExceptionCoverageTestFitness)2 Set (java.util.Set)1 MethodNoExceptionCoverageTestFitness (org.evosuite.coverage.method.MethodNoExceptionCoverageTestFitness)1 GoalComparator (org.evosuite.junit.naming.methods.GoalComparator)1