Search in sources :

Example 31 with MethodCoverageTestFitness

use of org.evosuite.coverage.method.MethodCoverageTestFitness 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)

Example 32 with MethodCoverageTestFitness

use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testTwoTestsMethodsWithSharedGoals.

@Test
public void testTwoTestsMethodsWithSharedGoals() {
    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", "getSomeStuff");
    test2.addCoveredGoal(goal2);
    MethodCoverageTestFitness goal3 = new MethodCoverageTestFitness("FooClass", "doFooBar");
    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("testGetSomeStuff", 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) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Example 33 with MethodCoverageTestFitness

use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testResolveConflictWithManyTests.

@Test
public void testResolveConflictWithManyTests() {
    // T1: A, B
    // T2: A, C
    // T3: A, D
    // T4: B, C
    // T5: B, D
    // T6: C, D
    Randomness.setSeed(0);
    MethodCoverageTestFitness methodGoal1 = new MethodCoverageTestFitness("FooClass", "foo(I)I");
    MethodCoverageTestFitness methodGoal2 = new MethodCoverageTestFitness("FooClass", "bar(I)I");
    MethodCoverageTestFitness methodGoal3 = new MethodCoverageTestFitness("FooClass", "zoo(I)I");
    MethodCoverageTestFitness methodGoal4 = new MethodCoverageTestFitness("FooClass", "gnu(I)I");
    TestCase test1 = new DefaultTestCase();
    test1.addCoveredGoal(methodGoal1);
    test1.addCoveredGoal(methodGoal2);
    TestCase test2 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 0));
    test2.addCoveredGoal(methodGoal1);
    test2.addCoveredGoal(methodGoal3);
    TestCase test3 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test3.addStatement(new IntPrimitiveStatement(test3, 1));
    test3.addCoveredGoal(methodGoal1);
    test3.addCoveredGoal(methodGoal4);
    TestCase test4 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test4.addStatement(new IntPrimitiveStatement(test4, 2));
    test4.addCoveredGoal(methodGoal2);
    test4.addCoveredGoal(methodGoal3);
    TestCase test5 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test5.addStatement(new IntPrimitiveStatement(test5, 3));
    test5.addCoveredGoal(methodGoal2);
    test5.addCoveredGoal(methodGoal4);
    TestCase test6 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test6.addStatement(new IntPrimitiveStatement(test6, 4));
    test6.addCoveredGoal(methodGoal3);
    test6.addCoveredGoal(methodGoal4);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    tests.add(test3);
    tests.add(test4);
    tests.add(test5);
    tests.add(test6);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testBarAndFoo", naming.getName(test1));
    assertEquals("testFooAndZoo", naming.getName(test2));
    assertEquals("testFooAndGnu", naming.getName(test3));
    assertEquals("testBarAndZoo", naming.getName(test4));
    assertEquals("testBarAndGnu", naming.getName(test5));
    assertEquals("testGnuAndZoo", naming.getName(test6));
}
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) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Example 34 with MethodCoverageTestFitness

use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testTwoTestsDifferOnlyInBranches.

@Test
public void testTwoTestsDifferOnlyInBranches() {
    Branch b1 = mock(Branch.class);
    BytecodeInstruction bi = mock(BytecodeInstruction.class);
    when(b1.getInstruction()).thenReturn(bi);
    TestCase test1 = new DefaultTestCase();
    MethodCoverageTestFitness methodGoal = new MethodCoverageTestFitness("FooClass", "toString");
    test1.addCoveredGoal(methodGoal);
    BranchCoverageTestFitness branchGoal1 = new BranchCoverageTestFitness(new BranchCoverageGoal(b1, true, "FooClass", "toStringBarFooBlubb", 0));
    test1.addCoveredGoal(branchGoal1);
    TestCase test2 = new DefaultTestCase();
    test2.addCoveredGoal(methodGoal);
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 0));
    BranchCoverageTestFitness branchGoal2 = new BranchCoverageTestFitness(new BranchCoverageGoal(b1, false, "FooClass", "toString", 0));
    test2.addCoveredGoal(branchGoal2);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testToString0", naming.getName(test1));
    assertEquals("testToString1", naming.getName(test2));
}
Also used : BranchCoverageTestFitness(org.evosuite.coverage.branch.BranchCoverageTestFitness) TestCase(org.evosuite.testcase.TestCase) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) Branch(org.evosuite.coverage.branch.Branch) MethodCoverageTestFitness(org.evosuite.coverage.method.MethodCoverageTestFitness) CoverageGoalTestNameGenerationStrategy(org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy) ArrayList(java.util.ArrayList) BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) BranchCoverageGoal(org.evosuite.coverage.branch.BranchCoverageGoal) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Example 35 with MethodCoverageTestFitness

use of org.evosuite.coverage.method.MethodCoverageTestFitness in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testOverloadedMethodWithArray.

@Test
public void testOverloadedMethodWithArray() {
    TestCase test1 = new DefaultTestCase();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "foo(I)");
    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", "foo([I)");
    test2.addCoveredGoal(goal2);
    TestCase test3 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test3.addStatement(new IntPrimitiveStatement(test3, 0));
    MethodCoverageTestFitness goal3 = new MethodCoverageTestFitness("FooClass", "foo([[I)");
    test3.addCoveredGoal(goal3);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    tests.add(test3);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testFooTakingInt", naming.getName(test1));
    assertEquals("testFooTakingIntArray", naming.getName(test2));
    assertEquals("testFooTakingIntArrayArray", naming.getName(test3));
}
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) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Aggregations

MethodCoverageTestFitness (org.evosuite.coverage.method.MethodCoverageTestFitness)48 Test (org.junit.Test)47 ArrayList (java.util.ArrayList)46 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)45 TestCase (org.evosuite.testcase.TestCase)45 CoverageGoalTestNameGenerationStrategy (org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy)36 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)35 OutputCoverageGoal (org.evosuite.coverage.io.output.OutputCoverageGoal)18 OutputCoverageTestFitness (org.evosuite.coverage.io.output.OutputCoverageTestFitness)18 ExceptionCoverageTestFitness (org.evosuite.coverage.exception.ExceptionCoverageTestFitness)11 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)11 InputCoverageGoal (org.evosuite.coverage.io.input.InputCoverageGoal)9 InputCoverageTestFitness (org.evosuite.coverage.io.input.InputCoverageTestFitness)9 MethodNoExceptionCoverageTestFitness (org.evosuite.coverage.method.MethodNoExceptionCoverageTestFitness)8 GoalComparator (org.evosuite.junit.naming.methods.GoalComparator)2 ClassWithOverloadedConstructor (com.examples.with.different.packagename.ClassWithOverloadedConstructor)1 Set (java.util.Set)1 Branch (org.evosuite.coverage.branch.Branch)1 BranchCoverageGoal (org.evosuite.coverage.branch.BranchCoverageGoal)1 BranchCoverageTestFitness (org.evosuite.coverage.branch.BranchCoverageTestFitness)1