pitest icon indicating copy to clipboard operation
pitest copied to clipboard

MutationResult.getSucceedingTests() always returns empty list

Open gibello opened this issue 5 years ago • 5 comments

Trying to write a MutationResultListener to generate specific reports. My class extends org.pitest.mutationtest.MutationResultListener .

In the handleMutationResult(ClassMutationResults results) method, I tried the following:

for (MutationResult mutation : results.getMutations()) {
    List<String> succedingTests = mutation.getSucceedingTests();
    for(String succedingtest : succedingTests) {
        out.println("Succeeding test:" + succedingtest);
    }
    List<String> killingTests = mutation.getKillingTests();
    for(String killingtest : killingTests) {
        out.println("Killing test:" + killingtest);
    }
}

The code is properly called (and getKillingTests() works fine).

But the list returned by getSucceedingTests() is always empty (either mutations are killed, or not, or part of them).

gibello avatar May 20 '19 16:05 gibello

Succeeding tests are only recorded when pitest is run in "test matrix" mode. Adding some javadoc to this effect would clearly be a good idea.

hcoles avatar May 20 '19 19:05 hcoles

Thanks; The fullMutationMatrix parameter is not documented... but I found it in the release notes. Problem, when set, my listener is never called: I get a message saying "Full mutation matrix is only supported in the output format XML", so I can't use any output format of my own.

gibello avatar May 21 '19 07:05 gibello

Did you solve your problem? A project of mine is stuck because of this same problem (Full mutation matrix support only XML). Why would that be desired? Any help would be appreciated.

victorgveloso avatar Apr 26 '20 05:04 victorgveloso

If you have a MutationResultListener of your own, the exclusion does not apply: your own MutationResultListener will perfectly run with fullMutationMatrix set (along with XML).

And, concerning succeeding tests without fullMutationMatrix, I finally considered all tests run did pass. Like this (but not sure it's what you need...):

List<String> succeedingTests = null;

// Retrieve succeeding tests list
// In "full matrix" mode, returned by getSucceedingTests()
// Otherwise, assume the list of tests run all pass when mutation survived...
if(this.listenerArguments.isFullMutationMatrix()) {
	succeedingTests = mutation.getSucceedingTests();
} else if (mutation.getStatus() == DetectionStatus.SURVIVED) {
	List<TestInfo> succeedingTestsInfo = mutation.getDetails().getTestsInOrder();
	for(TestInfo testInfo : succeedingTestsInfo) {
		if(succeedingTests == null) succeedingTests = new LinkedList<String>();
		succeedingTests.add(testInfo.getName());
	}
}

gibello avatar Apr 27 '20 07:04 gibello

Yes, it works but... I had to set outputFormats for both my format and XML. outputFormats = ['DetailedCSV','XML']. Otherwise the error "Full mutation matrix is only supported in the output format XML" appears. Searching for this string I found org.pitest.mutationtest.tooling.EntryPoint. There is a method with a hardcoded condition:

private void checkMatrixMode(ReportOptions data) {
    if (data.isFullMutationMatrix() && !data.getOutputFormats().contains("XML")) {
      throw new PitError("Full mutation matrix is only supported in the output format XML.");
    }
  }

It explicitly blocks the use of fullMutationMatrix for 'XML'-containing outputFormats only.

victorgveloso avatar Apr 28 '20 03:04 victorgveloso