use of org.evosuite.seeding.ObjectPool in project evosuite by EvoSuite.
the class PoolSystemTest method testPool.
@Test
public void testPool() throws IOException {
File f = File.createTempFile("EvoSuiteTestPool", null, FileUtils.getTempDirectory());
String filename = f.getAbsolutePath();
f.delete();
System.out.println(filename);
EvoSuite evosuite = new EvoSuite();
String targetClass = DependencyClass.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.SEARCH_BUDGET = 100000;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
ObjectPool pool = ObjectPool.getPoolFromTestSuite(best);
pool.writePool(filename);
System.out.println("EvolvedTestSuite:\n" + best);
resetStaticVariables();
setDefaultPropertiesForTestCases();
targetClass = OtherClass.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.P_OBJECT_POOL = 1.0;
Properties.OBJECT_POOLS = filename;
Properties.SEARCH_BUDGET = 10000;
ObjectPoolManager.getInstance().initialisePool();
// Properties.SEARCH_BUDGET = 50000;
command = new String[] { "-generateSuite", "-class", targetClass, "-Dobject_pools=" + filename };
result = evosuite.parseCommandLine(command);
ga = getGAFromResult(result);
TestSuiteChromosome best2 = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println("EvolvedTestSuite:\n" + best2);
Assert.assertEquals("Non-optimal coverage: ", 1d, best2.getCoverage(), 0.001);
f = new File(filename);
f.delete();
}
use of org.evosuite.seeding.ObjectPool in project evosuite by EvoSuite.
the class PoolSystemTest method testPoolWithException.
@Test
public void testPoolWithException() throws IOException, NoSuchMethodException, SecurityException {
File f = File.createTempFile("EvoSuiteTestPool", null, FileUtils.getTempDirectory());
String filename = f.getAbsolutePath();
f.delete();
System.out.println(filename);
EvoSuite evosuite = new EvoSuite();
String targetClass = DependencyClassWithException.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.getTargetClassAndDontInitialise();
TestCase test = new DefaultTestCase();
VariableReference instance = test.addStatement(new ConstructorStatement(test, new GenericConstructor(DependencyClassWithException.class.getConstructors()[0], DependencyClassWithException.class), new ArrayList<VariableReference>()));
VariableReference int42 = test.addStatement(new IntPrimitiveStatement(test, 42));
GenericMethod foo = new GenericMethod(DependencyClassWithException.class.getMethod("foo", int.class), DependencyClassWithException.class);
test.addStatement(new MethodStatement(test, foo, instance, Arrays.asList(new VariableReference[] { int42 })));
test.addStatement(new MethodStatement(test, foo, instance, Arrays.asList(new VariableReference[] { int42 })));
test.addStatement(new MethodStatement(test, foo, instance, Arrays.asList(new VariableReference[] { int42 })));
test.addStatement(new MethodStatement(test, foo, instance, Arrays.asList(new VariableReference[] { int42 })));
test.addStatement(new MethodStatement(test, foo, instance, Arrays.asList(new VariableReference[] { int42 })));
String[] command = new String[] { "-generateSuite", "-class", targetClass };
TestSuiteChromosome best = new TestSuiteChromosome();
best.addTest(test);
ObjectPool pool = new ObjectPool();
pool.addSequence(new GenericClass(DependencyClassWithException.class), test);
pool.writePool(filename);
System.out.println("EvolvedTestSuite:\n" + best);
resetStaticVariables();
setDefaultPropertiesForTestCases();
targetClass = ClassDependingOnExceptionClass.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.P_OBJECT_POOL = 0.8;
Properties.OBJECT_POOLS = filename;
ObjectPoolManager.getInstance().initialisePool();
// Properties.SEARCH_BUDGET = 50000;
command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
best = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println("EvolvedTestSuite:\n" + best);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
f = new File(filename);
f.delete();
}
use of org.evosuite.seeding.ObjectPool in project evosuite by EvoSuite.
the class TestSuiteGenerator method writeObjectPool.
private void writeObjectPool(TestSuiteChromosome suite) {
if (!Properties.WRITE_POOL.isEmpty()) {
LoggingUtils.getEvoLogger().info("* Writing sequences to pool");
ObjectPool pool = ObjectPool.getPoolFromTestSuite(suite);
pool.writePool(Properties.WRITE_POOL);
}
}
use of org.evosuite.seeding.ObjectPool in project evosuite by EvoSuite.
the class PoolSystemTest method testPoolWithSubClass.
@Test
public void testPoolWithSubClass() throws IOException {
File f = File.createTempFile("EvoSuiteTestPool", null, FileUtils.getTempDirectory());
String filename = f.getAbsolutePath();
f.delete();
System.out.println(filename);
EvoSuite evosuite = new EvoSuite();
String targetClass = DependencySubClass.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
// It takes a bit longer to cover the branch here
Properties.SEARCH_BUDGET = 50000;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
ObjectPool pool = ObjectPool.getPoolFromTestSuite(best);
pool.writePool(filename);
System.out.println("EvolvedTestSuite:\n" + best);
resetStaticVariables();
setDefaultPropertiesForTestCases();
targetClass = OtherClass.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.P_OBJECT_POOL = 1.0;
Properties.OBJECT_POOLS = filename;
ObjectPoolManager.getInstance().initialisePool();
command = new String[] { "-generateSuite", "-class", targetClass, "-Dobject_pools=" + filename };
result = evosuite.parseCommandLine(command);
ga = getGAFromResult(result);
best = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println("EvolvedTestSuite:\n" + best);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
f = new File(filename);
f.delete();
}
Aggregations