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);
}
Aggregations