STAMP-project / pitest-descartes

Descartes supports developers to improve their test suites by reporting weak spots in covered code
https://hal.archives-ouvertes.fr/hal-01870976/document
GNU Lesser General Public License v3.0
126 stars 21 forks source link

Add mutation returning method argument #136

Closed pkubowicz closed 3 years ago

pkubowicz commented 4 years ago

Java Stream API and Reactive Streams are increasingly popular and both Gregor and Descartes fail to produce good mutations for programs using those APIs (also for Fluent APIs, but this is addressed in #97).

One improvement that seems to be not too complicated yet effective is to mutate by returning the function argument.

Example

Let's take a typical map operator:

.map(filePath -> toAbsolutePath(filePath))

Here the lambda is Function<String, String>. Until now Pitest is only able to mutate into:

.map(filePath -> null)

This isn't very effective as a simple null-check will kill the mutation. In language like Kotlin you don't even need to insert null-checks manually.

A much better mutation would be to return the argument, thereby introducing a much more subtle 'bug':

.map(filePath -> filePath)

Further extensions

It would be great if the mutation was able to mutate functions with more than one argument, where at least one argument has the same type as the return value. But even mutating just Function<T, T> would be a significant improvement.

oscarlvp commented 4 years ago

Indeed a good addition. Thank you for the suggestion.

pkubowicz commented 4 years ago

The default Pitest engine contains code doing exactly what I mention: ArgumentPropagationMutator

oscarlvp commented 3 years ago

Included in version 1.3