Search in sources :

Example 1 with InputCoverageGoal

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

the class TestCoverageGoalNameGeneration method testTwoInputGoals.

@Test
public void testTwoInputGoals() {
    TestCase test = new DefaultTestCase();
    InputCoverageGoal inputGoal1 = new InputCoverageGoal("FooClass", "foo", 0, objectType(), REF_NONNULL);
    InputCoverageTestFitness goal1 = new InputCoverageTestFitness(inputGoal1);
    InputCoverageGoal inputGoal2 = new InputCoverageGoal("FooClass", "foo", 1, objectType(), REF_NULL);
    InputCoverageTestFitness goal2 = new InputCoverageTestFitness(inputGoal2);
    test.addCoveredGoal(goal1);
    test.addCoveredGoal(goal2);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    String generatedName = naming.getName(test);
    assertEquals("testFooWithNonNullAndNull", generatedName);
}
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) CoverageGoalTestNameGenerationStrategy(org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy) ArrayList(java.util.ArrayList) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) Test(org.junit.Test)

Example 2 with InputCoverageGoal

use of org.evosuite.coverage.io.input.InputCoverageGoal 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 InputCoverageGoal

use of org.evosuite.coverage.io.input.InputCoverageGoal 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 InputCoverageGoal

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

the class TestCoverageGoalNameGeneration method testResolveConflict3.

@Test
public void testResolveConflict3() {
    // T1: A, B
    // T2: A, C
    // T3: 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("testFooAndFooReturningZero", naming.getName(test1));
    assertEquals("testFooAndFooWithPositive", naming.getName(test2));
    // TODO: Is this acceptable? This happens because test 3 has no method goals
    assertEquals("testFooReturningZero", 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 5 with InputCoverageGoal

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

the class TestCoverageGoalNameGeneration method testResolveMethodNames.

@Test
public void testResolveMethodNames() {
    MethodCoverageTestFitness methodGoal = new MethodCoverageTestFitness("org.apache.commons.scxml.Builtin", "isMember(Ljava/util/Set;Ljava/lang/String;)Z");
    MethodNoExceptionCoverageTestFitness methodNoExGoal = new MethodNoExceptionCoverageTestFitness("org.apache.commons.scxml.Builtin", "isMember(Ljava/util/Set;Ljava/lang/String;)Z");
    OutputCoverageGoal outputGoalHelper1 = new OutputCoverageGoal("org.apache.commons.scxml.Builtin", "isMember(Ljava/util/Set;Ljava/lang/String;)Z", Type.BOOLEAN_TYPE, BOOL_FALSE);
    OutputCoverageTestFitness outputGoalFalse = new OutputCoverageTestFitness(outputGoalHelper1);
    OutputCoverageGoal outputGoalHelper2 = new OutputCoverageGoal("org.apache.commons.scxml.Builtin", "isMember(Ljava/util/Set;Ljava/lang/String;)Z", Type.BOOLEAN_TYPE, BOOL_TRUE);
    OutputCoverageTestFitness outputGoalTrue = new OutputCoverageTestFitness(outputGoalHelper2);
    InputCoverageGoal inputGoalHelper1 = new InputCoverageGoal("org.apache.commons.scxml.Builtin", "isMember(Ljava/util/Set;Ljava/lang/String;)Z", 0, Type.getType(Set.class), SET_EMPTY);
    InputCoverageTestFitness inputGoalEmptySet = new InputCoverageTestFitness(inputGoalHelper1);
    InputCoverageGoal inputGoalHelper2 = new InputCoverageGoal("org.apache.commons.scxml.Builtin", "isMember(Ljava/util/Set;Ljava/lang/String;)Z", 0, Type.getType(Set.class), SET_NONEMPTY);
    InputCoverageTestFitness inputGoalNonEmptySet = new InputCoverageTestFitness(inputGoalHelper2);
    InputCoverageGoal inputGoalHelper3 = new InputCoverageGoal("org.apache.commons.scxml.Builtin", "isMember(Ljava/util/Set;Ljava/lang/String;)Z", 1, Type.getType(String.class), STRING_NONEMPTY);
    InputCoverageTestFitness inputGoalStringNonEmpty = new InputCoverageTestFitness(inputGoalHelper3);
    TestCase test1 = new DefaultTestCase();
    test1.addCoveredGoal(methodGoal);
    test1.addCoveredGoal(methodNoExGoal);
    test1.addCoveredGoal(inputGoalEmptySet);
    test1.addCoveredGoal(inputGoalStringNonEmpty);
    test1.addCoveredGoal(outputGoalFalse);
    TestCase test2 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 0));
    test2.addCoveredGoal(methodGoal);
    test2.addCoveredGoal(methodNoExGoal);
    test2.addCoveredGoal(inputGoalNonEmptySet);
    test2.addCoveredGoal(inputGoalStringNonEmpty);
    test2.addCoveredGoal(outputGoalFalse);
    TestCase test3 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test3.addStatement(new IntPrimitiveStatement(test3, 1));
    test3.addCoveredGoal(methodGoal);
    test3.addCoveredGoal(methodNoExGoal);
    test3.addCoveredGoal(inputGoalNonEmptySet);
    test3.addCoveredGoal(inputGoalStringNonEmpty);
    test3.addCoveredGoal(outputGoalTrue);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    tests.add(test3);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testIsMemberWithEmptySet", naming.getName(test1));
    assertEquals("testIsMemberReturningFalse", naming.getName(test2));
    assertEquals("testIsMemberReturningTrue", naming.getName(test3));
}
Also used : Set(java.util.Set) InputCoverageTestFitness(org.evosuite.coverage.io.input.InputCoverageTestFitness) ArrayList(java.util.ArrayList) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) OutputCoverageGoal(org.evosuite.coverage.io.output.OutputCoverageGoal) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) 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) MethodNoExceptionCoverageTestFitness(org.evosuite.coverage.method.MethodNoExceptionCoverageTestFitness) OutputCoverageTestFitness(org.evosuite.coverage.io.output.OutputCoverageTestFitness) 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