use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.
the class OutputCoverageFitnessFunctionSystemTest method testOutputCoverageIgnoreHashCode.
@Test
public void testOutputCoverageIgnoreHashCode() {
EvoSuite evosuite = new EvoSuite();
String targetClass = ClassWithHashCode.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", 2, goals);
Assert.assertEquals("Non-optimal fitness: ", 0.0, best.getFitness(), 0.001);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.
the class OutputCoverageFitnessFunctionSystemTest method testOutputCoveragePrimitiveTypes.
public void testOutputCoveragePrimitiveTypes() {
EvoSuite evosuite = new EvoSuite();
String targetClass = MethodReturnsPrimitive.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", 24, goals);
Assert.assertEquals("Non-optimal fitness: ", 0.0, best.getFitness(), 0.001);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.
the class OutputCoverageFitnessFunctionSystemTest method testOutputCoverageArray.
@Test
public void testOutputCoverageArray() {
EvoSuite evosuite = new EvoSuite();
String targetClass = MethodReturnsArray.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", 15, goals);
Assert.assertEquals("Non-optimal fitness: ", 0.0, best.getFitness(), 0.001);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
use of org.evosuite.testsuite.TestSuiteChromosome 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.testsuite.TestSuiteChromosome 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);
}
Aggregations