use of org.evosuite.EvoSuite 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.EvoSuite in project evosuite by EvoSuite.
the class PoolSystemTest method testPoolDependency.
@Test
public void testPoolDependency() throws IOException {
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();
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
use of org.evosuite.EvoSuite 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.EvoSuite in project evosuite by EvoSuite.
the class ResetStaticFieldProxySystemTest method test.
@Test
public void test() {
EvoSuite evosuite = new EvoSuite();
String targetClass = StaticFooProxy.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println("EvolvedTestSuite:\n" + best);
double best_fitness = best.getFitness();
Assert.assertTrue("Optimal coverage not reached ", best_fitness == 0.0);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class StaticInitThrowsNullPointerSystemTest method testWithReset.
@Test
public void testWithReset() {
Properties.RESET_STATIC_FIELDS = true;
EvoSuite evosuite = new EvoSuite();
String targetClass = StaticInitThrowsNullPointer.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
assertTrue(result instanceof List);
List<?> list = (List<?>) result;
assertEquals(0, list.size());
}
Aggregations