use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class DeleteFileSystemTest method testDeleteOnExit.
@Test
public void testDeleteOnExit() 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 = DeleteFileExample.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 ReadWriteSystemPropertiesSystemTest method testReadLineSeparator.
@Test
public void testReadLineSeparator() {
EvoSuite evosuite = new EvoSuite();
String targetClass = ReadTimezone.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.SANDBOX = true;
Properties.REPLACE_CALLS = true;
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 cov = best.getCoverage();
Assert.assertEquals("Non-optimal coverage: ", 1d, cov, 0.001);
// now check the JUnit generation
List<TestCase> list = best.getTests();
int n = list.size();
Assert.assertTrue(n > 0);
// needed because it gets pulled down after the search
TestCaseExecutor.initExecutor();
try {
Sandbox.initializeSecurityManagerForSUT();
JUnitAnalyzer.removeTestsThatDoNotCompile(list);
} finally {
Sandbox.resetDefaultSecurityManager();
}
Assert.assertEquals(n, list.size());
TestGenerationResult tgr = TestGenerationResultBuilder.buildSuccessResult();
String code = tgr.getTestSuiteCode();
Assert.assertTrue("Test code:\n" + code, code.contains("user.timezone"));
/*
* This is tricky. The property 'debug' is read, but it does not exist.
* Ideally, we should still have in the test case a call to be sure the variable
* is set to null. But that would lead to a lot of problems :( eg cases
* in which we end up in reading hundreds of thousands variables that do not exist
*/
Assert.assertTrue("Test code:\n" + code, !code.contains("debug"));
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class ObjectPoolSystemTest method testDifficultClassWithWrongPoolFails.
@Ignore
@Test
public void testDifficultClassWithWrongPoolFails() {
EvoSuite evosuite = new EvoSuite();
String targetClass = DifficultClassWithoutCarving.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.P_OBJECT_POOL = 0.8;
Properties.CARVE_OBJECT_POOL = true;
Properties.SELECTED_JUNIT = ArrayConverterTestCase.class.getCanonicalName();
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);
Assert.assertTrue("Did not expect optimal coverage: ", best.getCoverage() < 1d);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class TypeSeedingSystemTest method testTypeExampleOff.
@Test
public void testTypeExampleOff() {
EvoSuite evosuite = new EvoSuite();
String targetClass = TypeExample.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.SEED_TYPES = false;
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);
int goals = TestSuiteGenerator.getFitnessFactories().get(0).getCoverageGoals().size();
Assert.assertEquals("Wrong number of goals: ", 4, goals);
Assert.assertTrue("Did not expect optimal coverage: ", best.getCoverage() < 1d);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class TypeSeedingSystemTest method testObjectToStringCase.
@Test
public void testObjectToStringCase() {
EvoSuite evosuite = new EvoSuite();
String targetClass = ObjectCastExample.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.SEED_TYPES = true;
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);
}
Aggregations