@Override public String getTargetClass() { return getClassName(); }
/** * This methods derive the dependencies between {@link MethodNoExceptionCoverageTestFitness} and branches. * Therefore, it is used to update 'this.dependencies' */ @SuppressWarnings("unchecked") private void addDependencies4MethodsNoException() { logger.debug("Added dependencies for MethodsNoException"); for (BranchCoverageTestFitness branch : this.dependencies.keySet()){ MethodNoExceptionCoverageTestFitness method = new MethodNoExceptionCoverageTestFitness(branch.getClassName(), branch.getMethod()); this.dependencies.get(branch).add((FitnessFunction<T>) method); } }
/** * This methods derive the dependencies between {@link MethodCoverageTestFitness} and branches. * Therefore, it is used to update 'this.dependencies' */ @SuppressWarnings("unchecked") private void addDependencies4Methods() { logger.debug("Added dependencies for Methods"); for (BranchCoverageTestFitness branch : this.dependencies.keySet()){ MethodCoverageTestFitness method = new MethodCoverageTestFitness(branch.getClassName(), branch.getMethod()); this.dependencies.get(branch).add((FitnessFunction<T>) method); } }
/** * This methods derive the dependencies between {@link CBranchTestFitness} and branches. * Therefore, it is used to update 'this.dependencies' */ @SuppressWarnings("unchecked") private void addDependencies4CBranch() { logger.debug("Added dependencies for CBranch"); CallGraph callGraph = DependencyAnalysis.getCallGraph(); for (BranchCoverageTestFitness branch : this.dependencies.keySet()) { for (CallContext context : callGraph.getMethodEntryPoint(branch.getClassName(), branch.getMethod())) { CBranchTestFitness cBranch = new CBranchTestFitness(branch.getBranchGoal(), context); this.dependencies.get(branch).add((FitnessFunction<T>) cBranch); logger.debug("Added context branch: " + cBranch.toString()); } } }
@Override public List<CBranchTestFitness> getCoverageGoals() { //TODO this creates duplicate goals. Momentary fixed using a Set, but it should be optimised Set<CBranchTestFitness> goals = new HashSet<>(); // retrieve set of branches BranchCoverageFactory branchFactory = new BranchCoverageFactory(); List<BranchCoverageTestFitness> branchGoals = branchFactory.getCoverageGoals(); CallGraph callGraph = DependencyAnalysis.getCallGraph(); // try to find all occurrences of this branch in the call tree for (BranchCoverageTestFitness branchGoal : branchGoals) { logger.info("Adding context branches for " + branchGoal.toString()); for (CallContext context : callGraph.getMethodEntryPoint(branchGoal.getClassName(), branchGoal.getMethod())) { goals.add(new CBranchTestFitness(branchGoal.getBranchGoal(), context)); } } logger.info("Created " + goals.size() + " goals"); return new ArrayList<CBranchTestFitness>(goals); } }
@Override public List<IBranchTestFitness> getCoverageGoals() { //TODO this creates duplicate goals. Momentary fixed using a Set. Set<IBranchTestFitness> goals = new HashSet<IBranchTestFitness>(); // retrieve set of branches BranchCoverageFactory branchFactory = new BranchCoverageFactory(); List<BranchCoverageTestFitness> branchGoals = branchFactory.getCoverageGoalsForAllKnownClasses(); CallGraph callGraph = DependencyAnalysis.getCallGraph(); // try to find all occurrences of this branch in the call tree for (BranchCoverageTestFitness branchGoal : branchGoals) { logger.info("Adding context branches for " + branchGoal.toString()); for (CallContext context : callGraph.getAllContextsFromTargetClass(branchGoal.getClassName(), branchGoal.getMethod())) { //if is not possible to reach this branch from the target class, continue. if(context.isEmpty()) continue; goals.add(new IBranchTestFitness(branchGoal.getBranchGoal(), context)); } } assert(goals.size()>=branchFactory.getCoverageGoals().size()); logger.info("Created " + goals.size() + " goals"); return new ArrayList<IBranchTestFitness>(goals); } }
branchlessMethodCoverageMap.put(goal.getClassName() + "." + goal.getMethod(), ff); } else {
private void initializeMaps(Set<FitnessFunction<T>> set){ for (FitnessFunction<T> ff : set) { BranchCoverageTestFitness goal = (BranchCoverageTestFitness) ff; // Skip instrumented branches - we only want real branches if(goal.getBranch() != null) { if(goal.getBranch().isInstrumented()) { continue; } } if (goal.getBranch() == null) { branchlessMethodCoverageMap.put(goal.getClassName() + "." + goal.getMethod(), ff); } else { if (goal.getBranchExpressionValue()) branchCoverageTrueMap.put(goal.getBranch().getActualBranchId(), ff); else branchCoverageFalseMap.put(goal.getBranch().getActualBranchId(), ff); } } }
/** * Initialize the set of known coverage goals */ protected void determineCoverageGoals(boolean updateArchive) { List<BranchCoverageTestFitness> goals = new BranchCoverageFactory().getCoverageGoals(); for (BranchCoverageTestFitness goal : goals) { // Skip instrumented branches - we only want real branches if(goal.getBranch() != null) { if(goal.getBranch().isInstrumented()) { continue; } } if(updateArchive && Properties.TEST_ARCHIVE) Archive.getArchiveInstance().addTarget(goal); if (goal.getBranch() == null) { branchlessMethodCoverageMap.put(goal.getClassName() + "." + goal.getMethod(), goal); } else { branchesId.add(goal.getBranch().getActualBranchId()); if (goal.getBranchExpressionValue()) branchCoverageTrueMap.put(goal.getBranch().getActualBranchId(), goal); else branchCoverageFalseMap.put(goal.getBranch().getActualBranchId(), goal); } } }