use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testConstructorAndOverloadedMethods.
@Test
public void testConstructorAndOverloadedMethods() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
// method goal
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>(LFooClass;)V");
TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "values()[B");
TestFitnessFunction goal3 = new MethodCoverageTestFitness("FooClass", "values([B)[B");
// exception goal
TestFitnessFunction goal4 = new ExceptionCoverageTestFitness("FooClass", "<init>(LFooClass;)V", ArrayIndexOutOfBoundsException.class, ExceptionCoverageTestFitness.ExceptionType.IMPLICIT);
// output goals
TestFitnessFunction goal5 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values()", Type.getType("[B"), ARRAY_NONEMPTY));
TestFitnessFunction goal6 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values([B)", Type.getType("[B"), ARRAY_EMPTY));
DefaultTestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(goal1);
test1.addCoveredGoal(goal2);
test1.addCoveredGoal(goal3);
test1.addCoveredGoal(goal5);
test1.addCoveredGoal(goal6);
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(goal3);
test2.addCoveredGoal(goal4);
test2.addCoveredGoal(goal5);
test2.addCoveredGoal(goal6);
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", "testFailsToCreateFooClassThrowsArrayIndexOutOfBoundsException", nameTest2);
}
use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class MockJOptionPaneShowInputDialogTest method testShowOptionDialog.
@Test
public void testShowOptionDialog() throws Exception {
TestSuiteChromosome suite = new TestSuiteChromosome();
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t1 = buildTestCase0(cl);
suite.addTest(t1);
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
Set<TestFitnessFunction> coveredGoals = suite.getCoveredGoals();
Assert.assertEquals(7, coveredGoals.size());
}
use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class MockJOptionPaneShowInternalInputDialogTest method testShowInternalInputDialog.
@Test
public void testShowInternalInputDialog() throws Exception {
TestSuiteChromosome suite = new TestSuiteChromosome();
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t1 = buildTestCase0(cl);
suite.addTest(t1);
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
Set<TestFitnessFunction> coveredGoals = suite.getCoveredGoals();
Assert.assertEquals(4, coveredGoals.size());
}
use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class MockJOptionPaneShowConfirmDialogTest method testShowConfirmDialogs.
@Test
public void testShowConfirmDialogs() throws Exception {
TestSuiteChromosome suite = new TestSuiteChromosome();
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t1 = buildTestCase0(cl);
suite.addTest(t1);
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
Set<TestFitnessFunction> coveredGoals = suite.getCoveredGoals();
Assert.assertEquals(5, coveredGoals.size());
}
use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class MockJOptionPaneShowInternalConfirmDialogTest method testShowInternalConfirmDialog.
@Test
public void testShowInternalConfirmDialog() throws Exception {
TestSuiteChromosome suite = new TestSuiteChromosome();
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t0 = buildTestCase0(cl);
TestCase t1 = buildTestCase1(cl);
suite.addTest(t0);
suite.addTest(t1);
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
Set<TestFitnessFunction> coveredGoals = suite.getCoveredGoals();
Assert.assertEquals(3, coveredGoals.size());
}
Aggregations