Search in sources :

Example 26 with CoverageGoalTestNameGenerationStrategy

use of org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testMethodWithInputGoals.

@Test
public void testMethodWithInputGoals() {
    TestCase test1 = new DefaultTestCase();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString");
    InputCoverageGoal inputGoal1 = new InputCoverageGoal("FooClass", "toString", 0, objectType(), REF_NULL);
    InputCoverageTestFitness goal2 = new InputCoverageTestFitness(inputGoal1);
    test1.addCoveredGoal(goal1);
    test1.addCoveredGoal(goal2);
    TestCase test2 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 0));
    test2.addCoveredGoal(goal1);
    InputCoverageGoal inputGoal2 = new InputCoverageGoal("FooClass", "toString", 0, objectType(), REF_NONNULL);
    InputCoverageTestFitness goal3 = new InputCoverageTestFitness(inputGoal2);
    test2.addCoveredGoal(goal3);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testToStringWithNull", naming.getName(test1));
    assertEquals("testToStringWithNonNull", naming.getName(test2));
}
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) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Example 27 with CoverageGoalTestNameGenerationStrategy

use of org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testStringOutputGoal.

@Test
public void testStringOutputGoal() {
    TestCase test = new DefaultTestCase();
    OutputCoverageGoal outputGoal1 = new OutputCoverageGoal("FooClass", "foo", stringType(), STRING_NONEMPTY);
    OutputCoverageTestFitness goal1 = new OutputCoverageTestFitness(outputGoal1);
    test.addCoveredGoal(goal1);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testFooReturningNonEmptyString", naming.getName(test));
}
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)

Example 28 with CoverageGoalTestNameGenerationStrategy

use of org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testUniqueMethod.

@Test
public void testUniqueMethod() {
    TestCase test = new DefaultTestCase();
    MethodCoverageTestFitness goal = new MethodCoverageTestFitness("FooClass", "toString");
    test.addCoveredGoal(goal);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    String generatedName = naming.getName(test);
    assertEquals("testToString", 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 29 with CoverageGoalTestNameGenerationStrategy

use of org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testMethodWithInputOutputGoals.

@Test
public void testMethodWithInputOutputGoals() {
    TestCase test1 = new DefaultTestCase();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString");
    InputCoverageGoal inputGoal1 = new InputCoverageGoal("FooClass", "toString", 0, objectType(), REF_NULL);
    InputCoverageTestFitness goal2 = new InputCoverageTestFitness(inputGoal1);
    test1.addCoveredGoal(goal1);
    test1.addCoveredGoal(goal2);
    TestCase test2 = new DefaultTestCase();
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 0));
    test2.addCoveredGoal(goal1);
    OutputCoverageGoal outputGoal2 = new OutputCoverageGoal("FooClass", "toString", objectType(), REF_NONNULL);
    OutputCoverageTestFitness goal3 = new OutputCoverageTestFitness(outputGoal2);
    test2.addCoveredGoal(goal3);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testToStringWithNull", naming.getName(test1));
    assertEquals("testToStringReturningNonNull", naming.getName(test2));
}
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 30 with CoverageGoalTestNameGenerationStrategy

use of org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testOverloadedConstructor.

@Test
public void testOverloadedConstructor() {
    TestCase test1 = new DefaultTestCase();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness(ClassWithOverloadedConstructor.class.getCanonicalName(), "<init>()");
    test1.addCoveredGoal(goal1);
    TestCase test2 = new DefaultTestCase();
    MethodCoverageTestFitness goal2 = new MethodCoverageTestFitness(ClassWithOverloadedConstructor.class.getCanonicalName(), "<init>(Ljava/lang/String;)");
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 0));
    test2.addCoveredGoal(goal2);
    TestCase test3 = new DefaultTestCase();
    MethodCoverageTestFitness goal3 = new MethodCoverageTestFitness(ClassWithOverloadedConstructor.class.getCanonicalName(), "<init>(II)");
    // Need to add statements to change hashCode
    test3.addStatement(new IntPrimitiveStatement(test3, 1));
    test3.addCoveredGoal(goal3);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    tests.add(test3);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    String generatedName1 = naming.getName(test1);
    String generatedName2 = naming.getName(test2);
    String generatedName3 = naming.getName(test3);
    // TODO: I would remove the WithOverloadedConstructor
    assertEquals("testCreatesClassWithOverloadedConstructorTakingNoArguments", generatedName1);
    assertEquals("testCreatesClassWithOverloadedConstructorTakingString", generatedName2);
    assertEquals("testCreatesClassWithOverloadedConstructorTaking2Arguments", generatedName3);
}
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) ClassWithOverloadedConstructor(com.examples.with.different.packagename.ClassWithOverloadedConstructor) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Aggregations

CoverageGoalTestNameGenerationStrategy (org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy)48 ArrayList (java.util.ArrayList)47 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)47 TestCase (org.evosuite.testcase.TestCase)47 Test (org.junit.Test)47 MethodCoverageTestFitness (org.evosuite.coverage.method.MethodCoverageTestFitness)36 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)27 OutputCoverageGoal (org.evosuite.coverage.io.output.OutputCoverageGoal)18 OutputCoverageTestFitness (org.evosuite.coverage.io.output.OutputCoverageTestFitness)18 InputCoverageGoal (org.evosuite.coverage.io.input.InputCoverageGoal)9 InputCoverageTestFitness (org.evosuite.coverage.io.input.InputCoverageTestFitness)9 MethodNoExceptionCoverageTestFitness (org.evosuite.coverage.method.MethodNoExceptionCoverageTestFitness)9 ExceptionCoverageTestFitness (org.evosuite.coverage.exception.ExceptionCoverageTestFitness)8 ClassWithOverloadedConstructor (com.examples.with.different.packagename.ClassWithOverloadedConstructor)2 File (java.io.File)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 LineCoverageTestFitness (org.evosuite.coverage.line.LineCoverageTestFitness)1