8

I am trying to exclude PIT from mutating I/O methods, such "close" and "flush". Here is my Maven configuration:

<plugin>
    <groupId>org.pitest</groupId>
    <artifactId>pitest-maven</artifactId>
    <version>1.1.3</version>
    <configuration>
        <targetClasses>
            <param>my.package.*.*</param>
        </targetClasses>
        <targetTests>                   
            <param>my.package.*.*</param>
        </targetTests>
        <excludedClasses>
            <param>my.generated.*</param>
            <param>**.*IT</param>                                
        </excludedClasses>
        <excludedMethods>
            <param>close</param>
            <param>flush</param>
        </excludedMethods>
        <reportSets>
            <reportSet>
                <reports>
                    <report>report</report>
                </reports>
            </reportSet>
        </reportSets>
    </configuration>
</plugin>

The excludedClasses seems to be working, but not the excludedMethods. i.e. the PIT result still says that remove the "close" and "flush" calls has no impact on the test result.

Question: What am I missing?

q3769
  • 192
  • 1
  • 12

1 Answers1

5

Excluded methods is used to avoid creating mutants within methods that match the supplied list of names.

What I think you wish to do is stop creating mutants that remove calls to close and flush methods. This can be done using the avoidCallsTo parameter.

henry
  • 5,923
  • 29
  • 46
  • Thanks, that is exactly what I wanted to achieve. However, when I tried the following: java.util.Scanner.closejava.util.logging The log entry works, but the Scanner entry doesn't. Any ideas? – q3769 Jun 24 '16 at 16:58
  • Is it a best practice to add methods like `close` and `flush` to `avoidCallsTo`, or should we somehow change our tests to fail if they aren't called? – ArtOfWarfare Apr 15 '21 at 18:06
  • @ArtOfWarfare its not really possible to answer that, depends on your codebase. If its important that your tests confirm close is called use avoidCallsTo. If you do, then don't add it. There's never really a single "best practice" for anything, each situation is different. – henry Apr 16 '21 at 19:28