pitest excludedMethods maven
Asked Answered
C

1

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?

Canso answered 10/6, 2016 at 7:29 Comment(0)
G
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.

Glaucescent answered 11/6, 2016 at 15:40 Comment(3)
Thanks, that is exactly what I wanted to achieve. However, when I tried the following: <avoidCallsTo> <avoidCallsTo>java.util.Scanner.close</avoidCallsTo <avoidCallsTo>java.util.logging</avoidCallsTo> </avoidCallsTo> The log entry works, but the Scanner entry doesn't. Any ideas?Canso
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?Vergievergil
@Vergievergil 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.Glaucescent

© 2022 - 2024 — McMap. All rights reserved.