Search in sources :

Example 6 with MethodNameMatcher

use of org.evosuite.coverage.MethodNameMatcher in project evosuite by EvoSuite.

the class BranchCoverageFactory method computeCoverageGoals.

/**
 * return coverage goals of the target class or of all the contextual branches, depending on the limitToCUT paramether
 * @param limitToCUT
 * @return
 */
private List<BranchCoverageTestFitness> computeCoverageGoals(boolean limitToCUT) {
    long start = System.currentTimeMillis();
    List<BranchCoverageTestFitness> goals = new ArrayList<BranchCoverageTestFitness>();
    // logger.info("Getting branches");
    for (String className : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).knownClasses()) {
        // when limitToCUT== true, if not the class under test of a inner/anonymous class, continue
        if (limitToCUT && !isCUT(className))
            continue;
        // when limitToCUT==false, consider all classes, but excludes libraries ones according the INSTRUMENT_LIBRARIES property
        if (!limitToCUT && (!Properties.INSTRUMENT_LIBRARIES && !DependencyAnalysis.isTargetProject(className)))
            continue;
        final MethodNameMatcher matcher = new MethodNameMatcher();
        // Branchless methods
        for (String method : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranchlessMethods(className)) {
            if (matcher.fullyQualifiedMethodMatches(method)) {
                goals.add(createRootBranchTestFitness(className, method));
            }
        }
        // Branches
        for (String methodName : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).knownMethods(className)) {
            if (!matcher.methodMatches(methodName)) {
                logger.info("Method " + methodName + " does not match criteria. ");
                continue;
            }
            for (Branch b : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).retrieveBranchesInMethod(className, methodName)) {
                if (!b.isInstrumented()) {
                    goals.add(createBranchCoverageTestFitness(b, true));
                    goals.add(createBranchCoverageTestFitness(b, false));
                }
            }
        }
    }
    goalComputationTime = System.currentTimeMillis() - start;
    return goals;
}
Also used : MethodNameMatcher(org.evosuite.coverage.MethodNameMatcher) ArrayList(java.util.ArrayList)

Aggregations

MethodNameMatcher (org.evosuite.coverage.MethodNameMatcher)6 ArrayList (java.util.ArrayList)4 Method (java.lang.reflect.Method)2 Type (org.objectweb.asm.Type)2 Inspector (org.evosuite.assertion.Inspector)1 Branch (org.evosuite.coverage.branch.Branch)1 BranchCoverageGoal (org.evosuite.coverage.branch.BranchCoverageGoal)1 BytecodeInstruction (org.evosuite.graphs.cfg.BytecodeInstruction)1