use of com.examples.with.different.packagename.coverage.ClassWithField in project evosuite by EvoSuite.
the class InputCoverageFitnessFunctionSystemTest method testInputCoverageClassWithField.
@Test
public void testInputCoverageClassWithField() throws NoSuchFieldException, NoSuchMethodException {
Class<?> sut = ClassWithField.class;
DefaultTestCase tc = new DefaultTestCase();
// ClassWithField classWithField0 = new ClassWithField();
GenericConstructor constructor = new GenericConstructor(sut.getConstructors()[0], sut);
ConstructorStatement constructorStatement = new ConstructorStatement(tc, constructor, Arrays.asList(new VariableReference[] {}));
VariableReference obj = tc.addStatement(constructorStatement);
// classWithField0.testFoo(classWithField0.BOOLEAN_FIELD);
FieldReference field = new FieldReference(tc, new GenericField(sut.getDeclaredField("BOOLEAN_FIELD"), sut), obj);
Method m = sut.getMethod("testFoo", new Class<?>[] { Boolean.TYPE });
GenericMethod gm = new GenericMethod(m, sut);
tc.addStatement(new MethodStatement(tc, gm, obj, Arrays.asList(new VariableReference[] { field })));
// classWithField0.BOOLEAN_FIELD = false;
VariableReference boolRef = tc.addStatement(new BooleanPrimitiveStatement(tc, false));
tc.addStatement(new AssignmentStatement(tc, field, boolRef));
tc.addStatement(new MethodStatement(tc, gm, obj, Arrays.asList(new VariableReference[] { field })));
Properties.TARGET_CLASS = sut.getCanonicalName();
Properties.JUNIT_TESTS = true;
TestSuiteChromosome testSuite = new TestSuiteChromosome();
testSuite.addTest(tc);
FitnessFunction ffunction = FitnessFunctions.getFitnessFunction(Properties.Criterion.INPUT);
assertEquals("Should be 0.0", 0.0, ffunction.getFitness(testSuite), 0.0);
assertEquals("Should be 1.0", 1.0, testSuite.getCoverage(ffunction), 0.0);
}
Aggregations