use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class MethodCoverageFitnessFunctionSystemTest method systemTestMethodCoverageInnerClasses.
@Test
public void systemTestMethodCoverageInnerClasses() {
EvoSuite evosuite = new EvoSuite();
String targetClass = ClassWithInnerClass.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 = TestGenerationStrategy.getFitnessFactories().get(0).getCoverageGoals().size();
Assert.assertEquals(4, goals);
System.out.println("EvolvedTestSuite:\n" + best);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class MethodTraceCoverageFitnessFunctionSystemTest method testMethodFitnessCompositionalExample.
public void testMethodFitnessCompositionalExample() {
EvoSuite evosuite = new EvoSuite();
String targetClass = Compositional.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();
System.out.println("EvolvedTestSuite:\n" + best);
// assuming single fitness function
int goals = TestGenerationStrategy.getFitnessFactories().get(0).getCoverageGoals().size();
Assert.assertEquals(4, goals);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
use of org.evosuite.EvoSuite 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.EvoSuite 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.EvoSuite 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);
}
Aggregations