use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class OutputCoverageFitnessFunctionSystemTest method testOutputCoverageObjectType.
public void testOutputCoverageObjectType() {
EvoSuite evosuite = new EvoSuite();
String targetClass = MethodReturnsObject.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();
int goals = 0;
for (TestFitnessFactory ff : TestGenerationStrategy.getFitnessFactories()) goals += ff.getCoverageGoals().size();
Assert.assertEquals("Unexpected number of goals", 14, goals);
// sub-optimal due to hashcode observer
Assert.assertEquals("Unexpected coverage: ", 0.888d, best.getCoverage(), 0.001);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class BaseDeterminismSystemTest method run.
private static String run(Class<?> target, Runnable initializer) {
SystemTestBase scaffolding = new SystemTestBase();
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
PrintStream outStream = new PrintStream(byteStream);
PrintStream latestOut = System.out;
System.setOut(outStream);
// @Before
scaffolding.setDefaultPropertiesForTestCases();
Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.LINE, Properties.Criterion.BRANCH, Properties.Criterion.EXCEPTION, Properties.Criterion.WEAKMUTATION, Properties.Criterion.OUTPUT, Properties.Criterion.METHOD, Properties.Criterion.METHODNOEXCEPTION, Properties.Criterion.CBRANCH };
if (initializer != null) {
initializer.run();
}
boolean defaultPrint = Properties.PRINT_TO_SYSTEM;
Properties.PRINT_TO_SYSTEM = true;
try {
EvoSuite evosuite = new EvoSuite();
String targetClass = target.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
evosuite.parseCommandLine(command);
} finally {
// @After
scaffolding.resetStaticVariables();
System.setOut(latestOut);
Properties.PRINT_TO_SYSTEM = defaultPrint;
}
return filter(byteStream.toString());
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class CurrentTimeSystemTest method testCurrentTimeViaDateParameter.
@Test
public void testCurrentTimeViaDateParameter() {
EvoSuite evosuite = new EvoSuite();
String targetClass = CurrentTimeViaDateParameter.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.REPLACE_CALLS = true;
// Properties.USE_DEPRECATED = false; // TODO why does the test pass only if USE_DEPRECATED is false???
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
java.lang.System.out.println("Test Suite: " + best.toString());
// 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 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.EvoSuite 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);
}
Aggregations