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;
}
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;
// }
}
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);
}
Aggregations