Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pitest doesn't recognize exception thrown by assert keyword by default #1322

Closed
Pfoerd opened this issue Apr 4, 2024 · 4 comments
Closed

Comments

@Pfoerd
Copy link
Contributor

Pfoerd commented Apr 4, 2024

Issue

Unit tests using the keyword "assert" (or the assert function of stdlib in Kotlin) fail when executed with Gradle but doesn't fail (and therefore produce false-positive survived mutations) when executed with Pitest.

This is a known behavior (see #442).

Unfortunately for developers this can be really hard to analyze as it is not commonly known that Gradle obviously is implicitly execution the unit tests with the "-ea" option.

So this issue is to discuss if it is possible to add the "-ea" option to Pitest execution by default?

Workaround

Manually add the "-ea" option when running Pitest, e.g. in Gradle by setting jvmArgs.add("-ea")

@Pfoerd Pfoerd changed the title Pitest doesn' Pitest doesn't recognize exception thrown by assert keyword by default Apr 4, 2024
@hcoles
Copy link
Owner

hcoles commented Apr 4, 2024

I think it would make most sense to raise this against https://github.com/szpak/gradle-pitest-plugin

The -ea flag is not set by default when running tests via maven or other tools. So setting it within pitest itself would potentially cause code to fail that ran green from those tools.

@Pfoerd
Copy link
Contributor Author

Pfoerd commented Apr 4, 2024

Ah okay I wasn't aware that Maven is not using this option by default. Okay I will raise this in the gradle Plugin. (I hope I have more success than with my other recent pull requests there, the project seems to have been very inactive for some time)

@Pfoerd Pfoerd closed this as completed Apr 4, 2024
@hcoles hcoles reopened this Apr 4, 2024
@hcoles
Copy link
Owner

hcoles commented Apr 4, 2024

You just prompted me to check my assumptions.

While I'm pretty sure that the maven surefire plugin never used to set -ea, I've just run a test with a recent version and the assertion failed.

So setting this by default in pitest does now make sense.

hcoles added a commit that referenced this issue Apr 8, 2024
hcoles added a commit that referenced this issue Apr 8, 2024
@hcoles
Copy link
Owner

hcoles commented Apr 12, 2024

released in 1.16.0

@hcoles hcoles closed this as completed Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants