use of org.evosuite.assertion.Assertion 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);
}
use of org.evosuite.assertion.Assertion in project evosuite by EvoSuite.
the class RegressionSuiteMinimizer method numFailingAssertions.
private int numFailingAssertions(RegressionTestChromosome test) {
int count = 0;
Set<Assertion> invalidAssertions = new HashSet<>();
ExecutionResult resultA = test.getLastExecutionResult();
ExecutionResult resultB = test.getLastRegressionExecutionResult();
for (Assertion assertion : test.getTheSameTestForTheOtherClassLoader().getTestCase().getAssertions()) {
for (OutputTrace<?> outputTrace : resultA.getTraces()) {
if (outputTrace.isDetectedBy(assertion)) {
logger.error("shouldn't be happening: assertion was failing on original version");
invalidAssertions.add(assertion);
break;
}
}
for (OutputTrace<?> outputTrace : resultB.getTraces()) {
if (outputTrace.isDetectedBy(assertion) && !invalidAssertions.contains(assertion)) {
count++;
break;
}
}
}
if (invalidAssertions.size() != 0) {
logger.warn("{} invalid assertion(s) to be removed", invalidAssertions);
for (Assertion assertion : invalidAssertions) {
test.getTheTest().getTestCase().removeAssertion(assertion);
test.getTheTest().setChanged(true);
test.updateClassloader();
}
}
int exDiffCount = 0;
if (resultA != null && resultB != null) {
exDiffCount = (int) RegressionExceptionHelper.compareExceptionDiffs(resultA.getCopyOfExceptionMapping(), resultB.getCopyOfExceptionMapping());
// logger.warn("exDiffCount: {}: \nmap1:{}\nmap2:{}\n",exDiffCount,resultA.getCopyOfExceptionMapping(),
// resultB.getCopyOfExceptionMapping());
count += exDiffCount;
if (exDiffCount > 0 && !test.exCommentsAdded) {
// logger.warn("Adding Exception Comments for test: \nmap1:{}\nmap2:{}\n",resultA.getCopyOfExceptionMapping(),
// resultB.getCopyOfExceptionMapping());
RegressionExceptionHelper.addExceptionAssertionComments(test, resultA.getCopyOfExceptionMapping(), resultB.getCopyOfExceptionMapping());
test.exCommentsAdded = true;
}
} else {
logger.error("resultA: {} | resultB: {}", resultA, resultB);
}
return count;
}
Aggregations