Search in sources :

Example 11 with OutputCoverageTestFitness

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

the class TestMethodNamingComplexExamples method testExactSameTests.

@Test
public void testExactSameTests() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
    // method goals
    TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "values([B)[B");
    TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "values()[B");
    // output goals
    TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values([B)", Type.getType("[B"), ARRAY_EMPTY));
    TestFitnessFunction goal5 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values()", Type.getType("[B"), ARRAY_NONEMPTY));
    DefaultTestCase test1 = new DefaultTestCase();
    test1.addCoveredGoal(goal1);
    test1.addCoveredGoal(goal2);
    test1.addCoveredGoal(goal4);
    test1.addCoveredGoal(goal5);
    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);
    test2.addCoveredGoal(goal5);
    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);
    assertEquals("Generated test name differs from expected", "testValuesTakingNoArgumentsReturningNonEmptyArray", nameTest1);
    assertEquals("Generated test name differs from expected", "testValuesTakingByteArrayReturningEmptyArray", 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)

Example 12 with OutputCoverageTestFitness

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

the class TestMethodNamingComplexExamples method testOverloadedMethodsNoArgs.

@Test
public void testOverloadedMethodsNoArgs() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
    // Method goals
    TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>(LFooClass;)V");
    TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "values([B)[B");
    TestFitnessFunction goal3 = new MethodCoverageTestFitness("FooClass", "values()[B");
    // Output goals for method values
    TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values([B)", Type.getType("[B"), ARRAY_EMPTY));
    TestFitnessFunction goal5 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values()", Type.getType("[B"), ARRAY_NONEMPTY));
    DefaultTestCase test1 = new DefaultTestCase();
    test1.addCoveredGoal(goal1);
    test1.addCoveredGoal(goal2);
    test1.addCoveredGoal(goal4);
    DefaultTestCase test2 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 2));
    test2.addCoveredGoal(goal1);
    test2.addCoveredGoal(goal3);
    test2.addCoveredGoal(goal5);
    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);
    assertEquals("Generated test name differs from expected", "testValuesTakingByteArray", nameTest1);
    assertEquals("Generated test name differs from expected", "testValuesTakingNoArguments", 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)

Example 13 with OutputCoverageTestFitness

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

the class TestMethodNamingComplexExamples method testIDNamingWithSameMethodGoals.

@Test
public void testIDNamingWithSameMethodGoals() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
    // method goals
    TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>()V");
    TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "getPublicID()Ljava/lang/String;");
    TestFitnessFunction goal3 = new MethodCoverageTestFitness("FooClass", "setPublicID(Ljava/lang/String;)LFooClass;");
    // output goals
    TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "getPublicID()", Type.getType("Ljava.lang.String;"), REF_NONNULL));
    TestFitnessFunction goal5 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "setPublicID(Ljava/lang/String;)", Type.getType("LFooClass;"), REF_NONNULL));
    DefaultTestCase test1 = new DefaultTestCase();
    // any statement to fool hashcode function
    test1.addStatement(new IntPrimitiveStatement(test1, 1));
    test1.addCoveredGoal(goal1);
    test1.addCoveredGoal(goal2);
    test1.addCoveredGoal(goal4);
    DefaultTestCase test2 = new DefaultTestCase();
    // any statement to fool hashcode function
    test2.addStatement(new IntPrimitiveStatement(test2, 2));
    test2.addCoveredGoal(goal1);
    test2.addCoveredGoal(goal3);
    test2.addCoveredGoal(goal5);
    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: testGetPublicID ?
    assertEquals("Generated test name differs from expected", "testGetPublicIDTakingNoArguments", nameTest1);
    // TODO: testSetPublicID ?
    assertEquals("Generated test name differs from expected", "testSetPublicIDTakingString", 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)

Example 14 with OutputCoverageTestFitness

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

the class TestMethodNamingComplexExamples method testOverloadedMethods.

@Test
public void testOverloadedMethods() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
    // Method goals
    TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>(LFooClass;)V");
    TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "values([B)[B");
    TestFitnessFunction goal3 = new MethodCoverageTestFitness("FooClass", "values([I)[B");
    // Output goals for method values
    TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values([B)", Type.getType("[B"), ARRAY_EMPTY));
    TestFitnessFunction goal5 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values([I)", Type.getType("[B"), ARRAY_NONEMPTY));
    DefaultTestCase test1 = new DefaultTestCase();
    test1.addCoveredGoal(goal1);
    test1.addCoveredGoal(goal2);
    test1.addCoveredGoal(goal4);
    DefaultTestCase test2 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 2));
    test2.addCoveredGoal(goal1);
    test2.addCoveredGoal(goal3);
    test2.addCoveredGoal(goal5);
    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);
    assertEquals("Generated test name differs from expected", "testValuesTakingByteArray", nameTest1);
    assertEquals("Generated test name differs from expected", "testValuesTakingIntArray", 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)

Example 15 with OutputCoverageTestFitness

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

the class TestCoverageGoalNameGeneration method testTwoOutputGoals.

@Test
public void testTwoOutputGoals() {
    TestCase test = new DefaultTestCase();
    OutputCoverageGoal outputGoal1 = new OutputCoverageGoal("FooClass", "toString", stringType(), STRING_EMPTY);
    OutputCoverageTestFitness goal1 = new OutputCoverageTestFitness(outputGoal1);
    OutputCoverageGoal outputGoal2 = new OutputCoverageGoal("FooClass", "bar", objectType(), REF_NONNULL);
    OutputCoverageTestFitness goal2 = new OutputCoverageTestFitness(outputGoal2);
    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("testBarReturningNonNullAndToStringReturningEmptyString", generatedName);
}
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)

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