use of org.evosuite.testsuite.TestSuiteChromosome 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.testsuite.TestSuiteChromosome 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.testsuite.TestSuiteChromosome 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.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.
the class MockJOptionPaneSystemTest method testShowConfirmDialogs2.
@Test
public void testShowConfirmDialogs2() throws Exception {
final String targetClass = AskUserShowConfirmDialogs2.class.getCanonicalName();
Properties.TEST_ARCHIVE = false;
Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH };
Properties.TARGET_CLASS = targetClass;
Properties.REPLACE_GUI = true;
Properties.MINIMIZE = true;
// As mutation operators remove instrumentation. This needs fixing first
Properties.ASSERTIONS = false;
EvoSuite evosuite = new EvoSuite();
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
Assert.assertNotNull(best);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
Assert.assertEquals("Non-optimal fitness: ", 0d, best.getFitness(), 0.001);
}
use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.
the class MockJOptionPaneSystemTest method testShowOptionDialogExample.
@Test
public void testShowOptionDialogExample() throws Exception {
final String targetClass = AskUserShowOptionDialog.class.getCanonicalName();
Properties.TEST_ARCHIVE = false;
Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH };
Properties.TARGET_CLASS = targetClass;
Properties.REPLACE_GUI = true;
Properties.MINIMIZE = true;
// As mutation operators remove instrumentation. This needs fixing first
Properties.ASSERTIONS = false;
EvoSuite evosuite = new EvoSuite();
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
Assert.assertNotNull(best);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
Assert.assertEquals("Non-optimal fitness: ", 0d, best.getFitness(), 0.001);
}
Aggregations