Search in sources :

Example 1 with ContractViolation

use of org.evosuite.contracts.ContractViolation in project evosuite by EvoSuite.

the class TestGenerationResultBuilder method setTestCase.

public void setTestCase(String name, String code, TestCase testCase, String comment, ExecutionResult result) {
    testCode.put(name, code);
    testCases.put(name, testCase);
    Set<Failure> failures = new LinkedHashSet<Failure>();
    for (ContractViolation violation : testCase.getContractViolations()) {
        failures.add(new Failure(violation));
    }
    if (!Properties.CHECK_CONTRACTS && result.hasUndeclaredException()) {
        int position = result.getFirstPositionOfThrownException();
        Throwable exception = result.getExceptionThrownAtPosition(position);
        failures.add(new Failure(exception, position, testCase));
    }
    contractViolations.put(name, failures);
    testComments.put(name, comment);
    testLineCoverage.put(name, result.getTrace().getCoveredLines());
    uncoveredLines.removeAll(result.getTrace().getCoveredLines());
    Set<BranchInfo> branchCoverage = new LinkedHashSet<BranchInfo>();
    for (int branchId : result.getTrace().getCoveredFalseBranches()) {
        Branch branch = BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranch(branchId);
        if (branch == null) {
            LoggingUtils.getEvoLogger().warn("Branch is null: " + branchId);
            continue;
        }
        BranchInfo info = new BranchInfo(branch.getClassName(), branch.getMethodName(), branch.getInstruction().getLineNumber(), false);
        branchCoverage.add(info);
    }
    for (int branchId : result.getTrace().getCoveredTrueBranches()) {
        Branch branch = BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranch(branchId);
        if (branch == null) {
            LoggingUtils.getEvoLogger().warn("Branch is null: " + branchId);
            continue;
        }
        BranchInfo info = new BranchInfo(branch.getClassName(), branch.getMethodName(), branch.getInstruction().getLineNumber(), true);
        branchCoverage.add(info);
    }
    testBranchCoverage.put(name, branchCoverage);
    uncoveredBranches.removeAll(branchCoverage);
    Set<MutationInfo> mutationCoverage = new LinkedHashSet<MutationInfo>();
    for (Assertion assertion : testCase.getAssertions()) {
        for (Mutation m : assertion.getKilledMutations()) {
            mutationCoverage.add(new MutationInfo(m));
        }
    }
    testMutantCoverage.put(name, mutationCoverage);
    uncoveredMutants.removeAll(mutationCoverage);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Assertion(org.evosuite.assertion.Assertion) ContractViolation(org.evosuite.contracts.ContractViolation) Branch(org.evosuite.coverage.branch.Branch) Mutation(org.evosuite.coverage.mutation.Mutation)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1 Assertion (org.evosuite.assertion.Assertion)1 ContractViolation (org.evosuite.contracts.ContractViolation)1 Branch (org.evosuite.coverage.branch.Branch)1 Mutation (org.evosuite.coverage.mutation.Mutation)1