Search in sources :

Example 1 with MethodTraceCoverageSuiteFitness

use of org.evosuite.coverage.method.MethodTraceCoverageSuiteFitness in project evosuite by EvoSuite.

the class CompositionalFitnessSystemTest method testCompositionalGetFitnessForSeveralFunctions.

@Test
public void testCompositionalGetFitnessForSeveralFunctions() {
    Properties.TARGET_CLASS = Compositional.class.getCanonicalName();
    TestSuiteChromosome c = new TestSuiteChromosome();
    MethodTraceCoverageSuiteFitness f1 = new MethodTraceCoverageSuiteFitness();
    c.addFitness(f1);
    c.setFitness(f1, ANY_DOUBLE_1);
    MethodNoExceptionCoverageSuiteFitness f2 = new MethodNoExceptionCoverageSuiteFitness();
    c.addFitness(f2);
    c.setFitness(f2, ANY_DOUBLE_2);
    OutputCoverageSuiteFitness f3 = new OutputCoverageSuiteFitness();
    c.addFitness(f3);
    c.setFitness(f3, ANY_DOUBLE_3);
    ExceptionCoverageSuiteFitness f4 = new ExceptionCoverageSuiteFitness();
    c.addFitness(f4);
    c.setFitness(f4, ANY_DOUBLE_4);
    double sum = ANY_DOUBLE_1 + ANY_DOUBLE_2 + ANY_DOUBLE_3 + ANY_DOUBLE_4;
    assertEquals(sum, c.getFitness(), 0.001);
}
Also used : OutputCoverageSuiteFitness(org.evosuite.coverage.io.output.OutputCoverageSuiteFitness) MethodNoExceptionCoverageSuiteFitness(org.evosuite.coverage.method.MethodNoExceptionCoverageSuiteFitness) ExceptionCoverageSuiteFitness(org.evosuite.coverage.exception.ExceptionCoverageSuiteFitness) Compositional(com.examples.with.different.packagename.Compositional) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) MethodTraceCoverageSuiteFitness(org.evosuite.coverage.method.MethodTraceCoverageSuiteFitness) MethodNoExceptionCoverageSuiteFitness(org.evosuite.coverage.method.MethodNoExceptionCoverageSuiteFitness) Test(org.junit.Test)

Example 2 with MethodTraceCoverageSuiteFitness

use of org.evosuite.coverage.method.MethodTraceCoverageSuiteFitness in project evosuite by EvoSuite.

the class PrivateReflectionSystemTest method testPrivateConstructor.

private TestSuiteChromosome testPrivateConstructor() {
    Properties.P_REFLECTION_ON_PRIVATE = 0.9;
    Properties.REFLECTION_START_PERCENT = 0.0;
    GeneticAlgorithm ga = do100percentLineTestOnStandardCriteriaWithMethodTrace(PrivateConstructor.class);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    assertTrue(!best.getTests().isEmpty());
    double cov = best.getCoverageInstanceOf(MethodCoverageSuiteFitness.class);
    Assert.assertEquals("Non-optimal method coverage: ", 1d, cov, 0.001);
    Optional<FitnessFunction<?>> ff = ga.getFitnessFunctions().stream().filter(m -> m instanceof MethodCoverageSuiteFitness).findAny();
    assertEquals(1, best.getNumOfCoveredGoals(ff.get()));
    cov = best.getCoverageInstanceOf(MethodTraceCoverageSuiteFitness.class);
    Assert.assertEquals("Non-optimal method trace coverage: ", 1d, cov, 0.001);
    ff = ga.getFitnessFunctions().stream().filter(m -> m instanceof MethodTraceCoverageSuiteFitness).findAny();
    assertEquals(1, best.getNumOfCoveredGoals(ff.get()));
    return best;
}
Also used : Arrays(java.util.Arrays) GeneticAlgorithm(org.evosuite.ga.metaheuristics.GeneticAlgorithm) RuntimeVariable(org.evosuite.statistics.RuntimeVariable) MethodCoverageFitnessFunctionSystemTest(org.evosuite.coverage.method.MethodCoverageFitnessFunctionSystemTest) OutputVariable(org.evosuite.statistics.OutputVariable) ArrayList(java.util.ArrayList) MethodTraceCoverageSuiteFitness(org.evosuite.coverage.method.MethodTraceCoverageSuiteFitness) FitnessFunction(org.evosuite.ga.FitnessFunction) SystemTestBase(org.evosuite.SystemTestBase) Properties(org.evosuite.Properties) com.examples.with.different.packagename.reflection(com.examples.with.different.packagename.reflection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) TestCaseExecutor(org.evosuite.testcase.execution.TestCaseExecutor) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) EvoSuite(org.evosuite.EvoSuite) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) MethodCoverageSuiteFitness(org.evosuite.coverage.method.MethodCoverageSuiteFitness) LineCoverageSuiteFitness(org.evosuite.coverage.line.LineCoverageSuiteFitness) Optional(java.util.Optional) Assert(org.junit.Assert) TestSuiteFitnessFunction(org.evosuite.testsuite.TestSuiteFitnessFunction) Assert.assertEquals(org.junit.Assert.assertEquals) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) MethodTraceCoverageSuiteFitness(org.evosuite.coverage.method.MethodTraceCoverageSuiteFitness) FitnessFunction(org.evosuite.ga.FitnessFunction) TestSuiteFitnessFunction(org.evosuite.testsuite.TestSuiteFitnessFunction) MethodCoverageSuiteFitness(org.evosuite.coverage.method.MethodCoverageSuiteFitness) GeneticAlgorithm(org.evosuite.ga.metaheuristics.GeneticAlgorithm)

Aggregations

MethodTraceCoverageSuiteFitness (org.evosuite.coverage.method.MethodTraceCoverageSuiteFitness)2 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)2 Test (org.junit.Test)2 Compositional (com.examples.with.different.packagename.Compositional)1 com.examples.with.different.packagename.reflection (com.examples.with.different.packagename.reflection)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 EvoSuite (org.evosuite.EvoSuite)1 Properties (org.evosuite.Properties)1 SystemTestBase (org.evosuite.SystemTestBase)1 ExceptionCoverageSuiteFitness (org.evosuite.coverage.exception.ExceptionCoverageSuiteFitness)1 OutputCoverageSuiteFitness (org.evosuite.coverage.io.output.OutputCoverageSuiteFitness)1 LineCoverageSuiteFitness (org.evosuite.coverage.line.LineCoverageSuiteFitness)1 MethodCoverageFitnessFunctionSystemTest (org.evosuite.coverage.method.MethodCoverageFitnessFunctionSystemTest)1 MethodCoverageSuiteFitness (org.evosuite.coverage.method.MethodCoverageSuiteFitness)1 MethodNoExceptionCoverageSuiteFitness (org.evosuite.coverage.method.MethodNoExceptionCoverageSuiteFitness)1 FitnessFunction (org.evosuite.ga.FitnessFunction)1