use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.
the class CurrentTimeSystemTest method testCurrentTimeViaCalendar1.
@Test
public void testCurrentTimeViaCalendar1() {
EvoSuite evosuite = new EvoSuite();
String targetClass = CurrentTimeViaCalendar1.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
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();
// 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.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.
the class CurrentTimeSystemTest method testCurrentTime1.
@Test
public void testCurrentTime1() {
EvoSuite evosuite = new EvoSuite();
String targetClass = CurrentTime.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
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();
// 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.testsuite.TestSuiteChromosome 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.testsuite.TestSuiteChromosome 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.testsuite.TestSuiteChromosome 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"));
}
Aggregations