Search in sources :

Example 26 with OutputCoverageTestFitness

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

the class TestMethodNamingComplexExamples method testConstructorAndOverloadedMethods.

@Test
public void testConstructorAndOverloadedMethods() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
    // method goal
    TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>(LFooClass;)V");
    TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "values()[B");
    TestFitnessFunction goal3 = new MethodCoverageTestFitness("FooClass", "values([B)[B");
    // exception goal
    TestFitnessFunction goal4 = new ExceptionCoverageTestFitness("FooClass", "<init>(LFooClass;)V", ArrayIndexOutOfBoundsException.class, ExceptionCoverageTestFitness.ExceptionType.IMPLICIT);
    // output goals
    TestFitnessFunction goal5 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values()", Type.getType("[B"), ARRAY_NONEMPTY));
    TestFitnessFunction goal6 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values([B)", Type.getType("[B"), ARRAY_EMPTY));
    DefaultTestCase test1 = new DefaultTestCase();
    test1.addCoveredGoal(goal1);
    test1.addCoveredGoal(goal2);
    test1.addCoveredGoal(goal3);
    test1.addCoveredGoal(goal5);
    test1.addCoveredGoal(goal6);
    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(goal3);
    test2.addCoveredGoal(goal4);
    test2.addCoveredGoal(goal5);
    test2.addCoveredGoal(goal6);
    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", "testFailsToCreateFooClassThrowsArrayIndexOutOfBoundsException", nameTest2);
}
Also used : ExceptionCoverageTestFitness(org.evosuite.coverage.exception.ExceptionCoverageTestFitness) 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)

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