use of org.evosuite.coverage.io.output.OutputCoverageGoal in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testExactSameTests.
@Test
public void testExactSameTests() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
// method goals
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "values([B)[B");
TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "values()[B");
// output goals
TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values([B)", Type.getType("[B"), ARRAY_EMPTY));
TestFitnessFunction goal5 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values()", Type.getType("[B"), ARRAY_NONEMPTY));
DefaultTestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(goal1);
test1.addCoveredGoal(goal2);
test1.addCoveredGoal(goal4);
test1.addCoveredGoal(goal5);
DefaultTestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 2));
test2.addCoveredGoal(goal1);
test2.addCoveredGoal(goal2);
test2.addCoveredGoal(goal4);
test2.addCoveredGoal(goal5);
ArrayList<TestCase> testCases = new ArrayList<>();
testCases.add(test1);
testCases.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(testCases);
String nameTest1 = naming.getName(test1);
String nameTest2 = naming.getName(test2);
assertEquals("Generated test name differs from expected", "testValuesTakingNoArgumentsReturningNonEmptyArray", nameTest1);
assertEquals("Generated test name differs from expected", "testValuesTakingByteArrayReturningEmptyArray", nameTest2);
}
use of org.evosuite.coverage.io.output.OutputCoverageGoal in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testOverloadedMethodsNoArgs.
@Test
public void testOverloadedMethodsNoArgs() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
// Method goals
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>(LFooClass;)V");
TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "values([B)[B");
TestFitnessFunction goal3 = new MethodCoverageTestFitness("FooClass", "values()[B");
// Output goals for method values
TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values([B)", Type.getType("[B"), ARRAY_EMPTY));
TestFitnessFunction goal5 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values()", Type.getType("[B"), ARRAY_NONEMPTY));
DefaultTestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(goal1);
test1.addCoveredGoal(goal2);
test1.addCoveredGoal(goal4);
DefaultTestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 2));
test2.addCoveredGoal(goal1);
test2.addCoveredGoal(goal3);
test2.addCoveredGoal(goal5);
ArrayList<TestCase> testCases = new ArrayList<>();
testCases.add(test1);
testCases.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(testCases);
String nameTest1 = naming.getName(test1);
String nameTest2 = naming.getName(test2);
assertEquals("Generated test name differs from expected", "testValuesTakingByteArray", nameTest1);
assertEquals("Generated test name differs from expected", "testValuesTakingNoArguments", nameTest2);
}
use of org.evosuite.coverage.io.output.OutputCoverageGoal in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testIDNamingWithSameMethodGoals.
@Test
public void testIDNamingWithSameMethodGoals() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
// method goals
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>()V");
TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "getPublicID()Ljava/lang/String;");
TestFitnessFunction goal3 = new MethodCoverageTestFitness("FooClass", "setPublicID(Ljava/lang/String;)LFooClass;");
// output goals
TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "getPublicID()", Type.getType("Ljava.lang.String;"), REF_NONNULL));
TestFitnessFunction goal5 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "setPublicID(Ljava/lang/String;)", Type.getType("LFooClass;"), REF_NONNULL));
DefaultTestCase test1 = new DefaultTestCase();
// any statement to fool hashcode function
test1.addStatement(new IntPrimitiveStatement(test1, 1));
test1.addCoveredGoal(goal1);
test1.addCoveredGoal(goal2);
test1.addCoveredGoal(goal4);
DefaultTestCase test2 = new DefaultTestCase();
// any statement to fool hashcode function
test2.addStatement(new IntPrimitiveStatement(test2, 2));
test2.addCoveredGoal(goal1);
test2.addCoveredGoal(goal3);
test2.addCoveredGoal(goal5);
ArrayList<TestCase> testCases = new ArrayList<>();
testCases.add(test1);
testCases.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(testCases);
String nameTest1 = naming.getName(test1);
String nameTest2 = naming.getName(test2);
// TODO: testGetPublicID ?
assertEquals("Generated test name differs from expected", "testGetPublicIDTakingNoArguments", nameTest1);
// TODO: testSetPublicID ?
assertEquals("Generated test name differs from expected", "testSetPublicIDTakingString", nameTest2);
}
use of org.evosuite.coverage.io.output.OutputCoverageGoal in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testOverloadedMethods.
@Test
public void testOverloadedMethods() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
// Method goals
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>(LFooClass;)V");
TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "values([B)[B");
TestFitnessFunction goal3 = new MethodCoverageTestFitness("FooClass", "values([I)[B");
// Output goals for method values
TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values([B)", Type.getType("[B"), ARRAY_EMPTY));
TestFitnessFunction goal5 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values([I)", Type.getType("[B"), ARRAY_NONEMPTY));
DefaultTestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(goal1);
test1.addCoveredGoal(goal2);
test1.addCoveredGoal(goal4);
DefaultTestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 2));
test2.addCoveredGoal(goal1);
test2.addCoveredGoal(goal3);
test2.addCoveredGoal(goal5);
ArrayList<TestCase> testCases = new ArrayList<>();
testCases.add(test1);
testCases.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(testCases);
String nameTest1 = naming.getName(test1);
String nameTest2 = naming.getName(test2);
assertEquals("Generated test name differs from expected", "testValuesTakingByteArray", nameTest1);
assertEquals("Generated test name differs from expected", "testValuesTakingIntArray", nameTest2);
}
use of org.evosuite.coverage.io.output.OutputCoverageGoal in project evosuite by EvoSuite.
the class TestCoverageGoalNameGeneration method testTwoOutputGoals.
@Test
public void testTwoOutputGoals() {
TestCase test = new DefaultTestCase();
OutputCoverageGoal outputGoal1 = new OutputCoverageGoal("FooClass", "toString", stringType(), STRING_EMPTY);
OutputCoverageTestFitness goal1 = new OutputCoverageTestFitness(outputGoal1);
OutputCoverageGoal outputGoal2 = new OutputCoverageGoal("FooClass", "bar", objectType(), REF_NONNULL);
OutputCoverageTestFitness goal2 = new OutputCoverageTestFitness(outputGoal2);
test.addCoveredGoal(goal1);
test.addCoveredGoal(goal2);
List<TestCase> tests = new ArrayList<>();
tests.add(test);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(tests);
String generatedName = naming.getName(test);
assertEquals("testBarReturningNonNullAndToStringReturningEmptyString", generatedName);
}
Aggregations