Search in sources :

Example 71 with TestFitnessFunction

use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.

the class OnlyBranchCoverageSuiteFitness method updateCoveredGoals.

@Override
public boolean updateCoveredGoals() {
    if (!Properties.TEST_ARCHIVE) {
        return false;
    }
    for (Integer branch : toRemoveBranchesT) {
        TestFitnessFunction f = branchCoverageTrueMap.remove(branch);
        if (f != null) {
            removedBranchesT.add(branch);
            if (removedBranchesF.contains(branch)) {
                totalBranches--;
            // if(isFullyCovered(f.getTargetClass(), f.getTargetMethod())) {
            // removeTestCall(f.getTargetClass(), f.getTargetMethod());
            // }
            }
        } else {
            throw new IllegalStateException("goal to remove not found");
        }
    }
    for (Integer branch : toRemoveBranchesF) {
        TestFitnessFunction f = branchCoverageFalseMap.remove(branch);
        if (f != null) {
            removedBranchesF.add(branch);
            if (removedBranchesT.contains(branch)) {
                totalBranches--;
            // if(isFullyCovered(f.getTargetClass(), f.getTargetMethod())) {
            // removeTestCall(f.getTargetClass(), f.getTargetMethod());
            // }
            }
        } else {
            throw new IllegalStateException("goal to remove not found");
        }
    }
    toRemoveBranchesF.clear();
    toRemoveBranchesT.clear();
    logger.info("Current state of archive: " + Archive.getArchiveInstance().toString());
    return true;
}
Also used : TestFitnessFunction(org.evosuite.testcase.TestFitnessFunction)

Example 72 with TestFitnessFunction

use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.

the class SearchStatistics method searchStarted.

/**
 * {@inheritDoc}
 */
@Override
public void searchStarted(GeneticAlgorithm<?> algorithm) {
    super.searchStarted(algorithm);
    StatisticEntry entry = statistics.get(statistics.size() - 1);
    entry.total_branches = Properties.TARGET_CLASS_PREFIX.isEmpty() ? BranchPool.getBranchCountForMemberClasses(Properties.TARGET_CLASS) : BranchPool.getBranchCountForPrefix(Properties.TARGET_CLASS_PREFIX);
    entry.branchless_methods = Properties.TARGET_CLASS_PREFIX.isEmpty() ? BranchPool.getBranchlessMethodsMemberClasses(Properties.TARGET_CLASS).size() : BranchPool.getBranchlessMethodsPrefix(Properties.TARGET_CLASS_PREFIX).size();
    entry.total_methods = Properties.TARGET_CLASS_PREFIX.isEmpty() ? CFGMethodAdapter.getNumMethodsMemberClasses(Properties.TARGET_CLASS) : CFGMethodAdapter.getNumMethodsPrefix(Properties.TARGET_CLASS_PREFIX);
    // FIXME: since this class is classified as 'deprecate' we are just assuming one fitness function
    List<? extends TestFitnessFunction> goals = TestSuiteGenerator.getFitnessFactory().get(0).getCoverageGoals();
    entry.total_goals = goals.size();
    // for (TestFitnessFunction f : TestSuiteGenerator.getFitnessFactory().getCoverageGoals()) {
    for (TestFitnessFunction f : goals) {
        if (f instanceof BranchCoverageTestFitness) {
            BranchCoverageTestFitness b = (BranchCoverageTestFitness) f;
            if (b.getBranch() != null && b.getBranch().isInstrumented()) {
            }
        }
    }
// removed the code below with the one above, in order to have these
// values for other criteria as well
// if (algorithm.getFitnessFunction() instanceof
// BranchCoverageSuiteFitness) {
// BranchCoverageSuiteFitness fitness = (BranchCoverageSuiteFitness)
// algorithm.getFitnessFunction();
// entry.total_branches = fitness.total_branches;
// entry.branchless_methods = fitness.branchless_methods;
// entry.total_methods = fitness.total_methods;
// }
}
Also used : BranchCoverageTestFitness(org.evosuite.coverage.branch.BranchCoverageTestFitness) TestFitnessFunction(org.evosuite.testcase.TestFitnessFunction)

Example 73 with TestFitnessFunction

use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.

the class MockTcpSystemTest method testReceiveTcp_noBranch.

// TODO put back once we properly handle boolean functions with TT
@Ignore
@Test
public void testReceiveTcp_noBranch() {
    EvoSuite evosuite = new EvoSuite();
    /*
            as there is no branch, covering both boolean outputs with online line coverage
            would not be possible. and so output coverage would be a necessity
         */
    String targetClass = ReceiveTcp_noBranch.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.SEARCH_BUDGET = 20000;
    Properties.VIRTUAL_NET = true;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.LINE, Properties.Criterion.OUTPUT };
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    Assert.assertTrue(result != null);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    List<TestFitnessFactory<? extends TestFitnessFunction>> list = TestGenerationStrategy.getFitnessFactories();
    Assert.assertEquals(2, list.size());
    Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
Also used : TestFitnessFunction(org.evosuite.testcase.TestFitnessFunction) EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) TestFitnessFactory(org.evosuite.coverage.TestFitnessFactory) Properties(org.evosuite.Properties) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)73 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)26 TestCase (org.evosuite.testcase.TestCase)24 Test (org.junit.Test)22 TestChromosome (org.evosuite.testcase.TestChromosome)21 ArrayList (java.util.ArrayList)20 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)15 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)12 MethodCoverageTestFitness (org.evosuite.coverage.method.MethodCoverageTestFitness)11 InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)11 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)9 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)9 TestFitnessFactory (org.evosuite.coverage.TestFitnessFactory)8 OutputCoverageGoal (org.evosuite.coverage.io.output.OutputCoverageGoal)8 OutputCoverageTestFitness (org.evosuite.coverage.io.output.OutputCoverageTestFitness)8 TestSuiteFitnessFunction (org.evosuite.testsuite.TestSuiteFitnessFunction)6 HashSet (java.util.HashSet)5 LinkedHashSet (java.util.LinkedHashSet)4 ExceptionCoverageTestFitness (org.evosuite.coverage.exception.ExceptionCoverageTestFitness)4 Properties (org.evosuite.Properties)3