Search in sources :

Example 11 with DefaultTestCase

use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testTwoUniqueMethodsWithLongNames.

@Test
public void testTwoUniqueMethodsWithLongNames() {
    TestCase test = new DefaultTestCase();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "loremIpsumDolorSitAmetConsectetuerAdipiscingElit()V");
    test.addCoveredGoal(goal1);
    MethodCoverageTestFitness goal2 = new MethodCoverageTestFitness("FooClass", "sedDiamNonummNibhEuismodTinciduntUtLaoreetDoloreMagnaAliquamEratVolutpat()V");
    test.addCoveredGoal(goal2);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    String generatedName = naming.getName(test);
    assertEquals("testLoremIpsumDolorSitAmetConsectetuerAdipiscingElit", 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 12 with DefaultTestCase

use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testResolveConflictWithTwoMethods.

@Test
public void testResolveConflictWithTwoMethods() {
    // T1: A, B
    // T2: A, C
    // T3: A, B, C
    TestCase test1 = new DefaultTestCase();
    MethodCoverageTestFitness methodGoal = new MethodCoverageTestFitness("FooClass", "foo(I)I");
    test1.addCoveredGoal(methodGoal);
    OutputCoverageGoal outputGoalHelper = new OutputCoverageGoal("FooClass", "foo(I)I", Type.INT_TYPE, NUM_ZERO);
    OutputCoverageTestFitness outputGoal1 = new OutputCoverageTestFitness(outputGoalHelper);
    test1.addCoveredGoal(outputGoal1);
    TestCase test2 = new DefaultTestCase();
    test2.addCoveredGoal(methodGoal);
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 0));
    InputCoverageGoal inputGoalHelper = new InputCoverageGoal("FooClass", "foo(I)I", 0, Type.INT_TYPE, NUM_POSITIVE);
    InputCoverageTestFitness inputGoal1 = new InputCoverageTestFitness(inputGoalHelper);
    test2.addCoveredGoal(inputGoal1);
    TestCase test3 = new DefaultTestCase();
    test3.addCoveredGoal(methodGoal);
    // Need to add statements to change hashCode
    test3.addStatement(new IntPrimitiveStatement(test3, 1));
    test3.addCoveredGoal(outputGoal1);
    test3.addCoveredGoal(inputGoal1);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    tests.add(test3);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testFooReturningZero", naming.getName(test1));
    assertEquals("testFooWithPositive", naming.getName(test2));
    assertEquals("testFooReturningZeroAndFooWithPositive", naming.getName(test3));
}
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 13 with DefaultTestCase

use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testUniqueConstructor.

@Test
public void testUniqueConstructor() {
    TestCase test = new DefaultTestCase();
    MethodCoverageTestFitness goal = new MethodCoverageTestFitness("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 14 with DefaultTestCase

use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testLineCoverageIsExcluded.

@Test
public void testLineCoverageIsExcluded() {
    TestCase test1 = new DefaultTestCase();
    MethodCoverageTestFitness methodGoal = new MethodCoverageTestFitness("FooClass", "toString()");
    test1.addCoveredGoal(methodGoal);
    LineCoverageTestFitness lineGoal1 = new LineCoverageTestFitness("FooClass", "toString()", 0);
    test1.addCoveredGoal(lineGoal1);
    TestCase test2 = new DefaultTestCase();
    test2.addCoveredGoal(methodGoal);
    // Need to add statements to change hashCode
    test2.addStatement(new IntPrimitiveStatement(test2, 0));
    LineCoverageTestFitness lineGoal2 = new LineCoverageTestFitness("FooClass", "toString()", 10);
    test2.addCoveredGoal(lineGoal2);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testToString0", naming.getName(test1));
    assertEquals("testToString1", naming.getName(test2));
}
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) LineCoverageTestFitness(org.evosuite.coverage.line.LineCoverageTestFitness) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Example 15 with DefaultTestCase

use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.

the class TestCoverageGoalNameGeneration method testTwoConstructorsSameClass.

@Test
public void testTwoConstructorsSameClass() {
    TestCase test = new DefaultTestCase();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "<init>()");
    test.addCoveredGoal(goal1);
    MethodCoverageTestFitness goal2 = new MethodCoverageTestFitness("FooClass", "<init>(I)");
    test.addCoveredGoal(goal2);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    String generatedName = naming.getName(test);
    assertEquals("testCreatesFooClassTakingNoArgumentsAndCreatesFooClassTakingInt", 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)

Aggregations

DefaultTestCase (org.evosuite.testcase.DefaultTestCase)347 Test (org.junit.Test)234 Constraint (org.evosuite.symbolic.expr.Constraint)101 TestCase (org.evosuite.testcase.TestCase)78 ArrayList (java.util.ArrayList)63 CoverageGoalTestNameGenerationStrategy (org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy)47 MethodCoverageTestFitness (org.evosuite.coverage.method.MethodCoverageTestFitness)45 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)41 VariableReference (org.evosuite.testcase.variable.VariableReference)37 TestCaseStringAppendString (com.examples.with.different.packagename.solver.TestCaseStringAppendString)27 TestCaseStringIndexOfString (com.examples.with.different.packagename.solver.TestCaseStringIndexOfString)27 TestCaseStringLastIndexOfString (com.examples.with.different.packagename.solver.TestCaseStringLastIndexOfString)27 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)27 OutputCoverageGoal (org.evosuite.coverage.io.output.OutputCoverageGoal)25 OutputCoverageTestFitness (org.evosuite.coverage.io.output.OutputCoverageTestFitness)25 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)18 GenericMethod (org.evosuite.utils.generic.GenericMethod)17 TestChromosome (org.evosuite.testcase.TestChromosome)16 Method (java.lang.reflect.Method)14 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)14