use of org.evosuite.utils.generic.GenericField in project evosuite by EvoSuite.
the class FactoryTestSystemTest method testAddFieldReuse.
@Test
public void testAddFieldReuse() throws ConstructionFailedException, NoSuchMethodException, SecurityException, NoSuchFieldException, ClassNotFoundException {
TestFactory testFactory = TestFactory.getInstance();
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(FactoryExample.class.getCanonicalName());
GenericField field = new GenericField(sut.getField("setMe"), sut);
DefaultTestCase test = new DefaultTestCase();
testFactory.addField(test, field, 0, 0);
assertEquals(2, test.size());
Properties.PRIMITIVE_REUSE_PROBABILITY = 1.0;
Properties.OBJECT_REUSE_PROBABILITY = 1.0;
testFactory.reset();
testFactory.addField(test, field, 2, 0);
assertEquals(3, test.size());
String code = test.toCode();
System.out.println(code);
assertTrue(code.contains("factoryExample0.setMe"));
assertFalse(code.contains("factoryExample1"));
}
use of org.evosuite.utils.generic.GenericField in project evosuite by EvoSuite.
the class FactoryTestSystemTest method testAddFieldAssignmentNoreuse.
@Test
public void testAddFieldAssignmentNoreuse() throws ConstructionFailedException, NoSuchMethodException, SecurityException, NoSuchFieldException, ClassNotFoundException {
TestFactory testFactory = TestFactory.getInstance();
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(FactoryExample.class.getCanonicalName());
GenericField field = new GenericField(sut.getField("setMe"), sut);
DefaultTestCase test = new DefaultTestCase();
testFactory.addFieldAssignment(test, field, 0, 0);
assertEquals(3, test.size());
testFactory.reset();
Properties.PRIMITIVE_REUSE_PROBABILITY = 0.0;
Properties.OBJECT_REUSE_PROBABILITY = 0.0;
testFactory.addFieldAssignment(test, field, 3, 0);
assertEquals(6, test.size());
String code = test.toCode();
System.out.println(code);
assertTrue(code.contains("factoryExample0.setMe"));
assertTrue(code.contains("factoryExample1.setMe"));
assertFalse(code.contains("factoryExample2"));
}
Aggregations