Search in sources :

Example 1 with OutputCoverageGoal

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

the class TestCoverageGoalNameGeneration method testInspectorOutputGoal.

@Test
public void testInspectorOutputGoal() {
    TestCase test = new DefaultTestCase();
    OutputCoverageGoal outputGoal1 = new OutputCoverageGoal("FooClass", "foo", stringType(), REF_NONNULL + ":" + "Bar" + ":" + "isFoo" + ":" + NUM_NEGATIVE);
    OutputCoverageTestFitness goal1 = new OutputCoverageTestFitness(outputGoal1);
    test.addCoveredGoal(goal1);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testFooReturningBarWhereIsFooIsNegative", 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 2 with OutputCoverageGoal

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

the class TestCoverageGoalNameGeneration method testResolveConflict2.

@Test
public void testResolveConflict2() {
    // T1: A, B -> B
    // T2: A, C -> C
    // T3: A, B, C -> B & C
    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();
    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("testFooReturningZeroAndFooWithPositive", 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 3 with OutputCoverageGoal

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

the class TestCoverageGoalNameGeneration method testResolveConflictWithTwoMethods.

@Test
public void testResolveConflictWithTwoMethods() {
    // T1: A, B
    // T2: A, C
    // T3: A, B, C
    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();
    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("testFooReturningZeroAndFooWithPositive", 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 4 with OutputCoverageGoal

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

the class TestCoverageGoalNameGeneration method testMethodWithOutputGoals.

@Test
public void testMethodWithOutputGoals() {
    TestCase test1 = new DefaultTestCase();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString");
    OutputCoverageGoal outputGoal1 = new OutputCoverageGoal("FooClass", "toString", objectType(), REF_NULL);
    OutputCoverageTestFitness goal2 = new OutputCoverageTestFitness(outputGoal1);
    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("testToStringReturningNull", naming.getName(test1));
    assertEquals("testToStringReturningNonNull", 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) 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 5 with OutputCoverageGoal

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

the class TestCoverageGoalNameGeneration method testOverloadedMethodDifferentArgArrayType.

@Test
public void testOverloadedMethodDifferentArgArrayType() {
    TestCase test1 = new DefaultTestCase();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "foo([B)");
    test1.addCoveredGoal(goal1);
    OutputCoverageTestFitness outputGoal = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "foo", stringType(), BOOL_FALSE));
    test1.addCoveredGoal(outputGoal);
    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);
    test2.addCoveredGoal(outputGoal);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testFooTakingByteArray", naming.getName(test1));
    assertEquals("testFooTakingIntArray", 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) 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)

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