Skip to content

Commit

Permalink
add "Covered by tests" list for every survived mutation in HTML report
Browse files Browse the repository at this point in the history
  • Loading branch information
vivganes committed Aug 10, 2024
1 parent dd84e8b commit d317859
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -51,10 +52,12 @@ private MutationResult xmlToResult(MutationXml xml) {
Location location = new Location(ClassName.fromString(xml.mutatedClass),
xml.mutatedMethod, xml.methodDescription);
MutationIdentifier id = new MutationIdentifier(location, xml.indexes, xml.mutator);
String[] killingTests = xml.killingTest == null ? new String[0] : new String[] { xml.killingTest };
String[] succeedingTests = xml.succeedingTests == null ? new String[0] : xml.succeedingTests.split(",");
return new MutationResult(new MutationDetails(id,
xml.sourceFile, xml.description,
xml.lineNumber, xml.blocks),
new MutationStatusTestPair(xml.numberOfTestsRun, DetectionStatus.valueOf(xml.status), xml.killingTest));
new MutationStatusTestPair(xml.numberOfTestsRun, DetectionStatus.valueOf(xml.status), Arrays.asList(killingTests), Arrays.asList(succeedingTests)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public String getKillingTestDescription() {
return getKillingTest().orElse("none");
}

public Boolean getSurvived() {
return this.status.getStatus() == DetectionStatus.SURVIVED;
}

@Override
public int hashCode() {
return Objects.hash(details, status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@
package org.pitest.mutationtest;

import static org.pitest.functional.prelude.Prelude.putToMap;
import static org.pitest.mutationtest.DetectionStatus.SURVIVED;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.pitest.coverage.TestInfo;
import org.pitest.functional.FCollection;
import org.pitest.mutationtest.engine.MutationDetails;

Expand All @@ -41,9 +44,24 @@ public void setStatusForMutation(final MutationDetails mutation,

public void setStatusForMutation(final MutationDetails mutation,
final MutationStatusTestPair status) {
this.mutationMap.put(mutation, status);
MutationStatusTestPair finalStatus = status;
if (status.getStatus().equals(SURVIVED)) {

List<TestInfo> testsInOrder = mutation.getTestsInOrder();
List<String> passingTests = new ArrayList<>();
for (TestInfo test : testsInOrder) {
passingTests.add(test.getName());
}
finalStatus = new MutationStatusTestPair(status.getNumberOfTestsRun(),
status.getStatus(),
status.getKillingTests(),
passingTests);

}
this.mutationMap.put(mutation, finalStatus);
}


public void setStatusForMutations(
final Collection<MutationDetails> mutations, final DetectionStatus status) {
mutations.forEach(putToMap(this.mutationMap, MutationStatusTestPair.notAnalysed(0, status)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<table class="src">

$sourceFile.lines:{ line |
$sourceFile.lines:{ line |

<tr>
<td class='$line.styles.lineCoverage$'>
Expand Down Expand Up @@ -42,7 +42,14 @@ $sourceFile.groups:{ group |

<a name='group$sourceFile$_$group.id$'/>

$group.mutations: { mutation | <p class='$mutation.status$'><span class='pop'>$i$.<span><b>$i$</b><br/><b>Location : </b>$mutation.details.location$<br/><b>Killed by : </b>$mutation.killingTestDescription$</span></span> $mutation.details.htmlSafeDescription$ &rarr; $mutation.statusDescription$</p> }$
$group.mutations: { mutation | <p class='$mutation.status$'><span class='pop'>$i$.<span><b>$i$</b><br/><b>Location : </b>$mutation.details.location$<br/><b>Killed by : </b>$mutation.killingTestDescription$</span></span> $mutation.details.htmlSafeDescription$ &rarr; $mutation.statusDescription$</span>
$if(mutation.survived)$
<p>Covered by tests: </p>
<ul>
$mutation.succeedingTests: { test | <li>$test$</li> }$
</ul>
$endif$
</p> }$
</td>
</tr>
}$
Expand Down

0 comments on commit d317859

Please sign in to comment.