Search in sources :

Example 6 with InputCoverageTestFitness

use of org.evosuite.coverage.io.input.InputCoverageTestFitness 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);
}
Also used : ExceptionCoverageTestFitness(org.evosuite.coverage.exception.ExceptionCoverageTestFitness) InputCoverageTestFitness(org.evosuite.coverage.io.input.InputCoverageTestFitness) InputCoverageGoal(org.evosuite.coverage.io.input.InputCoverageGoal) 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) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Example 7 with InputCoverageTestFitness

use of org.evosuite.coverage.io.input.InputCoverageTestFitness in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testMethodWithInputGoals.

@Test
public void testMethodWithInputGoals() {
    TestCase test1 = new DefaultTestCase();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString");
    InputCoverageGoal inputGoal1 = new InputCoverageGoal("FooClass", "toString", 0, objectType(), REF_NULL);
    InputCoverageTestFitness goal2 = new InputCoverageTestFitness(inputGoal1);
    test1.addCoveredGoal(goal1);
    test1.addCoveredGoal(goal2);
    TestCase test2 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 0));
    test2.addCoveredGoal(goal1);
    InputCoverageGoal inputGoal2 = new InputCoverageGoal("FooClass", "toString", 0, objectType(), REF_NONNULL);
    InputCoverageTestFitness goal3 = new InputCoverageTestFitness(inputGoal2);
    test2.addCoveredGoal(goal3);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testToStringWithNull", naming.getName(test1));
    assertEquals("testToStringWithNonNull", naming.getName(test2));
}
Also used : InputCoverageTestFitness(org.evosuite.coverage.io.input.InputCoverageTestFitness) TestCase(org.evosuite.testcase.TestCase) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) InputCoverageGoal(org.evosuite.coverage.io.input.InputCoverageGoal) MethodCoverageTestFitness(org.evosuite.coverage.method.MethodCoverageTestFitness) CoverageGoalTestNameGenerationStrategy(org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy) ArrayList(java.util.ArrayList) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Example 8 with InputCoverageTestFitness

use of org.evosuite.coverage.io.input.InputCoverageTestFitness in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testMethodWithInputOutputGoals.

@Test
public void testMethodWithInputOutputGoals() {
    TestCase test1 = new DefaultTestCase();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString");
    InputCoverageGoal inputGoal1 = new InputCoverageGoal("FooClass", "toString", 0, objectType(), REF_NULL);
    InputCoverageTestFitness goal2 = new InputCoverageTestFitness(inputGoal1);
    test1.addCoveredGoal(goal1);
    test1.addCoveredGoal(goal2);
    TestCase test2 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 0));
    test2.addCoveredGoal(goal1);
    OutputCoverageGoal outputGoal2 = new OutputCoverageGoal("FooClass", "toString", objectType(), REF_NONNULL);
    OutputCoverageTestFitness goal3 = new OutputCoverageTestFitness(outputGoal2);
    test2.addCoveredGoal(goal3);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testToStringWithNull", naming.getName(test1));
    assertEquals("testToStringReturningNonNull", naming.getName(test2));
}
Also used : InputCoverageTestFitness(org.evosuite.coverage.io.input.InputCoverageTestFitness) TestCase(org.evosuite.testcase.TestCase) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) InputCoverageGoal(org.evosuite.coverage.io.input.InputCoverageGoal) MethodCoverageTestFitness(org.evosuite.coverage.method.MethodCoverageTestFitness) 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) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Example 9 with InputCoverageTestFitness

use of org.evosuite.coverage.io.input.InputCoverageTestFitness in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testResolveBasicConflict.

@Test
public void testResolveBasicConflict() {
    // T1: A, B -> B
    // T2: A, C -> C
    // T3: A, C, B, D -> D
    TestCase test1 = new DefaultTestCase();
    MethodCoverageTestFitness methodGoal = new MethodCoverageTestFitness("FooClass", "foo(I)I");
    test1.addCoveredGoal(methodGoal);
    OutputCoverageGoal outputGoalHelper = new OutputCoverageGoal("FooClass", "foo(I)I", Type.INT_TYPE, NUM_ZERO);
    OutputCoverageTestFitness outputGoal1 = new OutputCoverageTestFitness(outputGoalHelper);
    test1.addCoveredGoal(outputGoal1);
    TestCase test2 = new DefaultTestCase();
    test2.addCoveredGoal(methodGoal);
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 0));
    InputCoverageGoal inputGoalHelper = new InputCoverageGoal("FooClass", "foo(I)I", 0, Type.INT_TYPE, NUM_POSITIVE);
    InputCoverageTestFitness inputGoal1 = new InputCoverageTestFitness(inputGoalHelper);
    test2.addCoveredGoal(inputGoal1);
    TestCase test3 = new DefaultTestCase();
    MethodCoverageTestFitness methodGoal2 = new MethodCoverageTestFitness("FooClass", "toString()L/java/lang/String;");
    test3.addCoveredGoal(methodGoal2);
    test3.addCoveredGoal(methodGoal);
    // Need to add statements to change hashCode
    test3.addStatement(new IntPrimitiveStatement(test3, 1));
    test3.addCoveredGoal(outputGoal1);
    test3.addCoveredGoal(inputGoal1);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    tests.add(test3);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testFooReturningZero", naming.getName(test1));
    assertEquals("testFooWithPositive", naming.getName(test2));
    assertEquals("testToString", naming.getName(test3));
}
Also used : InputCoverageTestFitness(org.evosuite.coverage.io.input.InputCoverageTestFitness) TestCase(org.evosuite.testcase.TestCase) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) InputCoverageGoal(org.evosuite.coverage.io.input.InputCoverageGoal) MethodCoverageTestFitness(org.evosuite.coverage.method.MethodCoverageTestFitness) 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) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Example 10 with InputCoverageTestFitness

use of org.evosuite.coverage.io.input.InputCoverageTestFitness in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testResolveConflictInputsOutputs.

@Test
public void testResolveConflictInputsOutputs() {
    // T1: A, I1, O1
    // T2: A, I2, O2
    // T3: A, I1, O2
    MethodCoverageTestFitness methodGoal = new MethodCoverageTestFitness("FooClass", "foo(I)I");
    OutputCoverageGoal outputGoalHelper1 = new OutputCoverageGoal("FooClass", "foo(I)I", Type.INT_TYPE, NUM_POSITIVE);
    OutputCoverageTestFitness outputGoal1 = new OutputCoverageTestFitness(outputGoalHelper1);
    OutputCoverageGoal outputGoalHelper2 = new OutputCoverageGoal("FooClass", "foo(I)I", Type.INT_TYPE, NUM_NEGATIVE);
    OutputCoverageTestFitness outputGoal2 = new OutputCoverageTestFitness(outputGoalHelper2);
    InputCoverageGoal inputGoalHelper1 = new InputCoverageGoal("FooClass", "foo(I)I", 0, Type.INT_TYPE, NUM_POSITIVE);
    InputCoverageTestFitness inputGoal1 = new InputCoverageTestFitness(inputGoalHelper1);
    InputCoverageGoal inputGoalHelper2 = new InputCoverageGoal("FooClass", "foo(I)I", 0, Type.INT_TYPE, NUM_NEGATIVE);
    InputCoverageTestFitness inputGoal2 = new InputCoverageTestFitness(inputGoalHelper2);
    TestCase test1 = new DefaultTestCase();
    test1.addCoveredGoal(methodGoal);
    test1.addCoveredGoal(inputGoal1);
    test1.addCoveredGoal(outputGoal1);
    TestCase test2 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 0));
    test2.addCoveredGoal(methodGoal);
    test2.addCoveredGoal(inputGoal2);
    test2.addCoveredGoal(outputGoal2);
    TestCase test3 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test3.addStatement(new IntPrimitiveStatement(test3, 1));
    test3.addCoveredGoal(methodGoal);
    test3.addCoveredGoal(inputGoal2);
    test3.addCoveredGoal(outputGoal1);
    TestCase test4 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test4.addStatement(new IntPrimitiveStatement(test4, 2));
    test4.addCoveredGoal(methodGoal);
    test4.addCoveredGoal(inputGoal1);
    test4.addCoveredGoal(outputGoal2);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    tests.add(test3);
    tests.add(test4);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testFooReturningPositiveAndFooWithPositive", naming.getName(test1));
    assertEquals("testFooReturningNegativeAndFooWithNegative", naming.getName(test2));
    assertEquals("testFooReturningPositiveAndFooWithNegative", naming.getName(test3));
    assertEquals("testFooReturningNegativeAndFooWithPositive", naming.getName(test4));
}
Also used : InputCoverageTestFitness(org.evosuite.coverage.io.input.InputCoverageTestFitness) InputCoverageGoal(org.evosuite.coverage.io.input.InputCoverageGoal) 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)

Aggregations

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