Search in sources :

Example 31 with TestCase

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

the class TestCoverageGoalNameGeneration method testOverloadedMethodWithObject.

@Test
public void testOverloadedMethodWithObject() {
    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(Ljava/util/List;)");
    test2.addCoveredGoal(goal2);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testFooTakingNoArguments", naming.getName(test1));
    assertEquals("testFooTakingList", 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) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement) Test(org.junit.Test)

Example 32 with TestCase

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

the class TestCoverageGoalNameGeneration method testMultipleMethods.

@Test
public void testMultipleMethods() throws NoSuchMethodException {
    TestCase test = new DefaultTestCase();
    GenericConstructor gc = new GenericConstructor(Object.class.getConstructor(), Object.class);
    VariableReference callee = test.addStatement(new ConstructorStatement(test, gc, new ArrayList<VariableReference>()));
    GenericMethod gm = new GenericMethod(Object.class.getMethod("toString"), Object.class);
    test.addStatement(new MethodStatement(test, gm, callee, new ArrayList<VariableReference>()));
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString()Ljava/lang/String;");
    test.addCoveredGoal(goal1);
    MethodCoverageTestFitness goal2 = new MethodCoverageTestFitness("FooClass", "foo()Ljava/lang/String;");
    test.addCoveredGoal(goal2);
    MethodCoverageTestFitness goal3 = new MethodCoverageTestFitness("FooClass", "bar()Ljava/lang/String;");
    test.addCoveredGoal(goal3);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    String generatedName = naming.getName(test);
    assertEquals("testToString", generatedName);
// TODO: What should be the name now? Need some heuristic, currently sorted alphabetically
// Better heuristic would consider other things, like e.g. which method has more goals covered
// or which one is the last one called?
}
Also used : ConstructorStatement(org.evosuite.testcase.statements.ConstructorStatement) MethodStatement(org.evosuite.testcase.statements.MethodStatement) VariableReference(org.evosuite.testcase.variable.VariableReference) ArrayList(java.util.ArrayList) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) GenericMethod(org.evosuite.utils.generic.GenericMethod) TestCase(org.evosuite.testcase.TestCase) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) MethodCoverageTestFitness(org.evosuite.coverage.method.MethodCoverageTestFitness) CoverageGoalTestNameGenerationStrategy(org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy) Test(org.junit.Test)

Example 33 with TestCase

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

the class TestCoverageGoalNameGeneration method testOverloadedMethodDifferentArgArrayType.

@Test
public void testOverloadedMethodDifferentArgArrayType() {
    TestCase test1 = new DefaultTestCase();
    MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "foo([B)");
    test1.addCoveredGoal(goal1);
    OutputCoverageTestFitness outputGoal = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "foo", stringType(), BOOL_FALSE));
    test1.addCoveredGoal(outputGoal);
    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);
    test2.addCoveredGoal(outputGoal);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test1);
    tests.add(test2);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testFooTakingByteArray", naming.getName(test1));
    assertEquals("testFooTakingIntArray", 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) 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 34 with TestCase

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

the class TestCoverageGoalNameGeneration method testResolveConflict3.

@Test
public void testResolveConflict3() {
    // T1: A, B
    // T2: A, C
    // T3: 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("testFooAndFooReturningZero", naming.getName(test1));
    assertEquals("testFooAndFooWithPositive", naming.getName(test2));
    // TODO: Is this acceptable? This happens because test 3 has no method goals
    assertEquals("testFooReturningZero", 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 35 with TestCase

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

the class TestCoverageGoalNameGeneration method testBooleanOutputGoal.

@Test
public void testBooleanOutputGoal() {
    TestCase test = new DefaultTestCase();
    OutputCoverageGoal outputGoal1 = new OutputCoverageGoal("FooClass", "foo", Type.BOOLEAN_TYPE, BOOL_TRUE);
    OutputCoverageTestFitness goal1 = new OutputCoverageTestFitness(outputGoal1);
    test.addCoveredGoal(goal1);
    List<TestCase> tests = new ArrayList<>();
    tests.add(test);
    CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
    assertEquals("testFooReturningTrue", 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)

Aggregations

TestCase (org.evosuite.testcase.TestCase)192 Test (org.junit.Test)119 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)90 ArrayList (java.util.ArrayList)67 CoverageGoalTestNameGenerationStrategy (org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy)47 MethodCoverageTestFitness (org.evosuite.coverage.method.MethodCoverageTestFitness)45 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)43 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)39 VariableReference (org.evosuite.testcase.variable.VariableReference)26 OutputCoverageGoal (org.evosuite.coverage.io.output.OutputCoverageGoal)25 OutputCoverageTestFitness (org.evosuite.coverage.io.output.OutputCoverageTestFitness)25 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)24 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)17 TestChromosome (org.evosuite.testcase.TestChromosome)17 InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)15 Ignore (org.junit.Ignore)15 VariableReferenceImpl (org.evosuite.testcase.variable.VariableReferenceImpl)14 GenericMethod (org.evosuite.utils.generic.GenericMethod)12 ExceptionCoverageTestFitness (org.evosuite.coverage.exception.ExceptionCoverageTestFitness)11 InputCoverageGoal (org.evosuite.coverage.io.input.InputCoverageGoal)10