Skip to content

Pitest Mutation Listener

Luca Böhm edited this page Dec 19, 2023 · 3 revisions

Mutation Result Listener

General

By implementing the MutationResultListener Interface, one can create a custom Mutation Result Listener (example).

Methods and how we could use them

In the interface there are three methods given:

  • runStart: This method gets called at the start of a pitest run. We could use it to check for needed directorys and setting up data structures the our plugin needs.
  • handleMutationResult: This is the most interresting method, sice we could use it to get the information pitest gathers, without having to scrape the xml and html outputs. Pitest automaticaly calls this method for each listener thats registerd (more on that below) and gives them all the mutation results it has gathered (see code).
  • runEnd This method gets called at the end of the pitest run. We could use it to safe the gathere information and populate the UI.

Register the Listener

To enable Pitest to use custom listeners, one needs to follow the following steps:

  1. The listeners and thier factorys must have a unique name.
  2. The factorys must be listed in a file using the qualifiyed name of the factory (pitest example), so in our case it would be com.amos.pitmutationmate.pitmutationmate.reporting.MyMutationResultListenerFactory. The file must be named org.pitest.mutationtest.MutationResultListenerFactory.
  3. This file must then be packed into a JAR file
  4. The JAR file must then be located in classpath:META-INF/services
  5. The build script must be adapted so that the JAR file gets added