Search in sources :

Example 41 with MethodCoverageTestFitness

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

the class TestCoverageGoalNameGeneration method testConstructorWithFullyQualifiedClassName.

@Test
public void testConstructorWithFullyQualifiedClassName() {
    TestCase test = new DefaultTestCase();
    MethodCoverageTestFitness goal = new MethodCoverageTestFitness("org.package.name.FooClass", "<init>()");
    test.addCoveredGoal(goal);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    String generatedName = naming.getName(test);
    assertEquals("testCreatesFooClass", generatedName);
}
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) Test(org.junit.Test)

Example 42 with MethodCoverageTestFitness

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

the class TestCoverageGoalNameGeneration method testOverloadedMethod.

@Test
public void testOverloadedMethod() {
    TestCase test1 = new DefaultTestCase();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "foo()");
    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(II)");
    test3.addCoveredGoal(goal3);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    tests.add(test3);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testFooTakingNoArguments", naming.getName(test1));
    assertEquals("testFooTakingInt", naming.getName(test2));
    assertEquals("testFooTaking2Arguments", 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)

Example 43 with MethodCoverageTestFitness

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

the class TestCoverageGoalNameGeneration method testTwoUniqueMethods.

@Test
public void testTwoUniqueMethods() {
    TestCase test = new DefaultTestCase();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "foo");
    test.addCoveredGoal(goal1);
    MethodCoverageTestFitness goal2 = new MethodCoverageTestFitness("FooClass", "bar");
    test.addCoveredGoal(goal2);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    String generatedName = naming.getName(test);
    assertEquals("testBarAndFoo", generatedName);
}
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) Test(org.junit.Test)

Example 44 with MethodCoverageTestFitness

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

the class TestGoalComparator method testComparatorList.

@Test
public void testComparatorList() {
    GoalComparator comparator = new GoalComparator();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString()");
    ExceptionCoverageTestFitness goal2 = new ExceptionCoverageTestFitness("FooClass", "toString()", MockArithmeticException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
    OutputCoverageGoal outputGoal = new OutputCoverageGoal("FooClass", "toString", Type.getType("Ljava.lang.String;"), IOCoverageConstants.REF_NONNULL);
    OutputCoverageTestFitness goal3 = new OutputCoverageTestFitness(outputGoal);
    List<TestFitnessFunction> goals = new ArrayList<>();
    goals.add(goal1);
    goals.add(goal2);
    goals.add(goal3);
    Collections.sort(goals, comparator);
    assertEquals(goal2, goals.get(0));
}
Also used : ExceptionCoverageTestFitness(org.evosuite.coverage.exception.ExceptionCoverageTestFitness) MethodCoverageTestFitness(org.evosuite.coverage.method.MethodCoverageTestFitness) TestFitnessFunction(org.evosuite.testcase.TestFitnessFunction) ArrayList(java.util.ArrayList) OutputCoverageTestFitness(org.evosuite.coverage.io.output.OutputCoverageTestFitness) OutputCoverageGoal(org.evosuite.coverage.io.output.OutputCoverageGoal) GoalComparator(org.evosuite.junit.naming.methods.GoalComparator) Test(org.junit.Test)

Example 45 with MethodCoverageTestFitness

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

the class TestGoalComparator method testCompareExceptionMethod.

@Test
public void testCompareExceptionMethod() {
    GoalComparator comparator = new GoalComparator();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString()");
    ExceptionCoverageTestFitness goal2 = new ExceptionCoverageTestFitness("FooClass", "toString()", MockArithmeticException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
    assertEquals(1, comparator.compare(goal1, goal2));
}
Also used : ExceptionCoverageTestFitness(org.evosuite.coverage.exception.ExceptionCoverageTestFitness) MethodCoverageTestFitness(org.evosuite.coverage.method.MethodCoverageTestFitness) GoalComparator(org.evosuite.junit.naming.methods.GoalComparator) 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