Search in sources :

Example 6 with MethodNoExceptionCoverageTestFitness

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

the class TestCoverageGoalNameGeneration method testTwoTestsTwoMethodsOneWithException.

@Test
public void testTwoTestsTwoMethodsOneWithException() {
    TestCase test1 = new DefaultTestCase();
    TestCase test2 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 0));
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "foo");
    test1.addCoveredGoal(goal1);
    test2.addCoveredGoal(goal1);
    MethodCoverageTestFitness goal2 = new MethodCoverageTestFitness("FooClass", "bar()I");
    test1.addCoveredGoal(goal2);
    test2.addCoveredGoal(goal2);
    ExceptionCoverageTestFitness goal3 = new ExceptionCoverageTestFitness("FooClass", "bar()I", RuntimeException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT);
    test1.addCoveredGoal(goal3);
    MethodNoExceptionCoverageTestFitness goal4 = new MethodNoExceptionCoverageTestFitness("FooClass", "bar()I");
    test2.addCoveredGoal(goal4);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    String generatedName1 = naming.getName(test1);
    String generatedName2 = naming.getName(test2);
    assertEquals("testBarThrowsRuntimeException", generatedName1);
    assertEquals("testBar", generatedName2);
}
Also used : ExceptionCoverageTestFitness(org.evosuite.coverage.exception.ExceptionCoverageTestFitness) MethodNoExceptionCoverageTestFitness(org.evosuite.coverage.method.MethodNoExceptionCoverageTestFitness) 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) ArrayList(java.util.ArrayList) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Aggregations

MethodCoverageTestFitness (org.evosuite.coverage.method.MethodCoverageTestFitness)6 MethodNoExceptionCoverageTestFitness (org.evosuite.coverage.method.MethodNoExceptionCoverageTestFitness)6 ArrayList (java.util.ArrayList)5 CoverageGoalTestNameGenerationStrategy (org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy)5 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)5 TestCase (org.evosuite.testcase.TestCase)5 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)5 Test (org.junit.Test)5 ExceptionCoverageTestFitness (org.evosuite.coverage.exception.ExceptionCoverageTestFitness)4 Set (java.util.Set)1 InputCoverageGoal (org.evosuite.coverage.io.input.InputCoverageGoal)1 InputCoverageTestFitness (org.evosuite.coverage.io.input.InputCoverageTestFitness)1 OutputCoverageGoal (org.evosuite.coverage.io.output.OutputCoverageGoal)1 OutputCoverageTestFitness (org.evosuite.coverage.io.output.OutputCoverageTestFitness)1 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)1