-
Notifications
You must be signed in to change notification settings - Fork 354
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
Enum constructors should not be mutated #556
Comments
Unless I am mis-understanding what you mean by Take the Java code:
The class file creates the following code when decompiled:
As you can see the constructor is called multiple times in 1 JVM. The only static part of the enumeration is the enum definitions. |
Yes the constructor is called once per enum instance and will not (barring some horrific trickery) be called again. It is effectively static initializer code. |
I was just about to create an issue for this very situation. I am unable to kill any mutation related to member variable assignments in an enum constructor, though unit tests fail when manually setting the member variables to their default values. |
This may be related, I'm getting weird results for |
@christianhujer That is a little strange. It could relate to the recent changes made to the coverage system. Are you seeing this across Java versions? |
I haven't checked different versions yet. I am observing this using:
I will create a small isolated test case covering all situations where I'm observing this, which is:
And I'll run this through different JDK versions. Once I'm done, I'll share the results here. |
To help with understanding the issue and where it comes from, I've created a small git repository to demonstrate the issue. Here it is: https://github.com/christianhujer/pitest-bug-556 In any case, the coverage reports of Pitest report a reduced line coverage for enums.
|
I could not observe the original issue that enum constructors should not be mutated. Should I create a new ticket like "enum constructors and constants should not be reported as 'not covered' by line coverage"? |
@christianhujer The active mutators would not be triggered by the code in these enums - if you put a sysout call in there you should see it mutated by the void calls mutator. Thanks for the example project. I'd assumed this was an issue with the new coverage implementation introduced in 1.4.6, but I tried it with 1.4.5 an and saw the same behaviour. Not sure what's causing this, but yes please do raise a separate ticket as this is a different issue than the one in the title. |
adds filter for enum constructors for #556
Code in enum constructors should be treated as static initializer code as it will only be run once per JVM, effecting both mutant insertion and code coverage.
The text was updated successfully, but these errors were encountered: