use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class CurrentTimeSystemTest method testTimeOperation.
@Test
public void testTimeOperation() {
EvoSuite evosuite = new EvoSuite();
String targetClass = TimeOperation.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.REPLACE_CALLS = true;
// , "-assertions"
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
// assuming single fitness function
int goals = TestGenerationStrategy.getFitnessFactories().get(0).getCoverageGoals().size();
Assert.assertEquals("Wrong number of goals: ", 3, goals);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class SUTWithSystemExitSystemTest method testSystemExit.
@Test
public void testSystemExit() {
java.lang.System.setSecurityManager(new SafeExit());
EvoSuite evosuite = new EvoSuite();
String targetClass = CallExit.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.REPLACE_CALLS = true;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
evosuite.parseCommandLine(command);
assertFalse(SafeExit.calledExit);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class IssueStaticInitializerWithTryCatchSystemTest method runTheTest.
private void runTheTest(boolean reset) {
Properties.RESET_STATIC_FIELDS = reset;
EvoSuite evosuite = new EvoSuite();
String targetClass = ClassWithStaticInitializerTryCatch.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();
Assert.assertNotNull(best);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class DeleteFileSystemTest method testDeleteOnThread.
@Test
public void testDeleteOnThread() throws IOException {
String tmpdir = System.getProperty("java.io.tmpdir");
File toDelete = new File(tmpdir + File.separator + "this_file_should_not_be_deleted_by_evosuite");
FileUtils.write(toDelete, "BlahBlah");
assertTrue(toDelete.exists());
EvoSuite evosuite = new EvoSuite();
String targetClass = DeleteFileThread.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.SANDBOX = true;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
evosuite.parseCommandLine(command);
assertTrue("File has been deleted: " + toDelete.getAbsolutePath(), toDelete.exists());
toDelete.delete();
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class DeleteFileSystemTest method testDeleteStaticNoReset.
@Test
public void testDeleteStaticNoReset() throws IOException {
Properties.RESET_STATIC_FIELDS = false;
String tmpdir = System.getProperty("java.io.tmpdir");
File toDelete = new File(tmpdir + File.separator + "this_file_should_not_be_deleted_by_evosuite");
FileUtils.write(toDelete, "BlahBlah");
assertTrue(toDelete.exists());
EvoSuite evosuite = new EvoSuite();
String targetClass = DeleteInStaticInitializer.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.SANDBOX = true;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
evosuite.parseCommandLine(command);
assertTrue("File has been deleted: " + toDelete.getAbsolutePath(), toDelete.exists());
toDelete.delete();
}
Aggregations