Search in sources :

Example 16 with ExceptionCoverageTestFitness

use of org.evosuite.coverage.exception.ExceptionCoverageTestFitness in project evosuite by EvoSuite.

the class MOSA method calculateFitness.

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
protected void calculateFitness(T c) {
    for (FitnessFunction<T> fitnessFunction : this.fitnessFunctions) {
        double value = fitnessFunction.getFitness(c);
        if (value == 0.0) {
            // ((TestChromosome)c).addCoveredGoals(fitnessFunction);
            updateArchive(c, fitnessFunction);
        }
    }
    if (ArrayUtil.contains(Properties.CRITERION, Criterion.EXCEPTION)) {
        // if one of the coverage criterion is Criterion.EXCEPTION,
        // then we have to analyze the results of the execution do look
        // for generated exceptions
        List<ExceptionCoverageTestFitness> list = deriveCoveredExceptions(c);
        for (ExceptionCoverageTestFitness exp : list) {
            // new covered exceptions (goals) have to be added to the archive
            updateArchive(c, (FitnessFunction<T>) exp);
            if (!fitnessFunctions.contains(exp)) {
                // let's update the list of fitness functions
                this.fitnessFunctions.add((FitnessFunction<T>) exp);
                // let's update the newly discovered exceptions to ExceptionCoverageFactory
                ExceptionCoverageFactory.getGoals().put(exp.toString(), exp);
            }
        }
    }
    notifyEvaluation(c);
    // update the time needed to reach the max coverage
    budgetMonitor.checkMaxCoverage(this.archive.keySet().size());
}
Also used : ExceptionCoverageTestFitness(org.evosuite.coverage.exception.ExceptionCoverageTestFitness)

Aggregations

ExceptionCoverageTestFitness (org.evosuite.coverage.exception.ExceptionCoverageTestFitness)16 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)13 MethodCoverageTestFitness (org.evosuite.coverage.method.MethodCoverageTestFitness)11 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)11 TestCase (org.evosuite.testcase.TestCase)11 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)9 MethodNoExceptionCoverageTestFitness (org.evosuite.coverage.method.MethodNoExceptionCoverageTestFitness)8 CoverageGoalTestNameGenerationStrategy (org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy)8 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)4 GoalComparator (org.evosuite.junit.naming.methods.GoalComparator)3 OutputCoverageGoal (org.evosuite.coverage.io.output.OutputCoverageGoal)2 OutputCoverageTestFitness (org.evosuite.coverage.io.output.OutputCoverageTestFitness)2 ClassWithOverloadedConstructor (com.examples.with.different.packagename.ClassWithOverloadedConstructor)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 InputCoverageGoal (org.evosuite.coverage.io.input.InputCoverageGoal)1 InputCoverageTestFitness (org.evosuite.coverage.io.input.InputCoverageTestFitness)1 TestChromosome (org.evosuite.testcase.TestChromosome)1