use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class MockJOptionPaneShowInternalMessageDialogTest method testShowInternalMessageDialog.
@Test
public void testShowInternalMessageDialog() throws Exception {
TestSuiteChromosome suite = new TestSuiteChromosome();
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t0 = buildTestCase0(cl);
TestCase t1 = buildTestCase1(cl);
suite.addTest(t0);
suite.addTest(t1);
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
Set<TestFitnessFunction> coveredGoals = suite.getCoveredGoals();
Assert.assertEquals(3, coveredGoals.size());
}
use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class MockJOptionPaneShowMessageDialogTest method testShowMessageDialog1.
@Test
public void testShowMessageDialog1() throws Exception {
TestSuiteChromosome suite = new TestSuiteChromosome();
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t0 = buildTestCase1TrueBranch(cl);
TestCase t1 = buildTestCase1FalseBranch(cl);
suite.addTest(t0);
suite.addTest(t1);
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
Set<TestFitnessFunction> coveredGoals = suite.getCoveredGoals();
Assert.assertEquals(3, coveredGoals.size());
}
use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class MockJOptionPaneShowOptionDialogTest method testShowInputDialogs.
@Test
public void testShowInputDialogs() throws Exception {
TestSuiteChromosome suite = new TestSuiteChromosome();
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t1 = buildTestCase0(cl);
suite.addTest(t1);
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
Set<TestFitnessFunction> coveredGoals = suite.getCoveredGoals();
Assert.assertEquals(2, coveredGoals.size());
}
use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class MockJOptionPaneTest method testCoveredGoals.
@Test
public void testCoveredGoals() throws Exception {
Properties.TIMEOUT = Integer.MAX_VALUE;
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t0 = buildTestCase0(cl);
TestCase t1 = buildTestCase1(cl);
TestSuiteChromosome suite = new TestSuiteChromosome();
suite.addTest(t0);
suite.addTest(t1);
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
Set<TestFitnessFunction> coveredGoals = suite.getCoveredGoals();
Assert.assertEquals(3, coveredGoals.size());
}
use of org.evosuite.testcase.TestFitnessFunction in project evosuite by EvoSuite.
the class OutputCoverageSuiteFitness method getFitness.
/**
* {@inheritDoc}
* <p/>
* Execute all tests and count covered output goals
*/
@Override
public double getFitness(AbstractTestSuiteChromosome<? extends ExecutableChromosome> suite) {
logger.trace("Calculating test suite fitness");
double fitness = 0.0;
List<ExecutionResult> results = runTestSuite(suite);
boolean hasTimeoutOrTestException = false;
for (ExecutionResult result : results) {
if (result.hasTimeout() || result.hasTestException()) {
hasTimeoutOrTestException = true;
break;
}
}
Set<TestFitnessFunction> setOfCoveredGoals = new LinkedHashSet<>();
if (hasTimeoutOrTestException) {
logger.info("Test suite has timed out, setting fitness to max value " + totalGoals);
fitness = totalGoals;
} else
fitness = computeDistance(results, setOfCoveredGoals);
int coveredGoals = setOfCoveredGoals.size() + removedGoals.size();
if (totalGoals > 0)
suite.setCoverage(this, (double) coveredGoals / (double) totalGoals);
else
suite.setCoverage(this, 1.0);
suite.setNumOfCoveredGoals(this, coveredGoals);
printStatusMessages(suite, coveredGoals, fitness);
updateIndividual(this, suite, fitness);
assert (coveredGoals <= totalGoals) : "Covered " + coveredGoals + " vs total goals " + totalGoals;
assert (fitness >= 0.0);
assert (fitness != 0.0 || coveredGoals == totalGoals) : "Fitness: " + fitness + ", " + "coverage: " + coveredGoals + "/" + totalGoals;
assert (suite.getCoverage(this) <= 1.0) && (suite.getCoverage(this) >= 0.0) : "Wrong coverage value " + suite.getCoverage(this);
return fitness;
}
Aggregations