Issue #14019: Kill mutation in SuppressWithNearbyTextFilter#15941
Issue #14019: Kill mutation in SuppressWithNearbyTextFilter#15941akankshat05 wants to merge 1 commit into
Conversation
| /** | ||
| * Calls the filter on two real input files and verifies that the | ||
| * filter caches the file path only once. Ensures 'cachedFileAbsolutePath' remains | ||
| * unchanged and validates a single call to retrieve file text. |
There was a problem hiding this comment.
I understand that in web there are huge amount of examples that shows such type of testing where numerous mocks are used to hit specific code, testing just for testing, with little business values and little chance to be understood by next engineer.
Our project used this model in past, that is why you see here and there still bad examples. After many years we saw that such tests are just problems.
We are switched to BDD style testing, that is more expensive in execution time but has significantly more value and ease of maintainability.
So we need to redo this test method to use config in Input file.
Your case is not trivial, so let me guide you.
We need to create testing Filter module that is defined in same package as this Test class. This filter module will remove a file that is referenced in violation.
So some Check will do 2 violations in Input file. In config you will place two filter modules (target filter and filter that removes file). Input should be located in regular folder as all others. Before execution you will copy Input of repository to some temp file. Filters executed in order of declaration, so removal filter should be last. On second violation Input file will be removed, so loading of it will do exception if cache doesn't not happening.
There was a problem hiding this comment.
Okay, I will update the test.
There was a problem hiding this comment.
Look at examples of internal testing modules https://github.com/checkstyle/checkstyle/tree/master/src/test/java/com/puppycrawl/tools/checkstyle/internal/testmodules
If looks at commits involved in introduction of such modules, you can see how we migrated from unit testing to Input based https://github.com/checkstyle/checkstyle/commits/master/src/test/java/com/puppycrawl/tools/checkstyle/internal/testmodules
Latest example 2d5bfc1
There was a problem hiding this comment.
Just FYI, is case you think we are crazy to not use mocks https://testing.googleblog.com/2024/02/increase-test-fidelity-by-avoiding-mocks.html
0986a35 to
b3d5fad
Compare
| if (!path.contains(File.separatorChar + "grammar" + File.separatorChar) | ||
| && !path.contains(File.separatorChar + "internal" + File.separatorChar)) { | ||
| && !path.contains(File.separatorChar + "internal" + File.separatorChar) | ||
| && !path.contains(File.separatorChar + "filters" + File.separatorChar)) { |
There was a problem hiding this comment.
Please revert this.
We can put internal test input to existing folder "internal".
| /////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| package com.puppycrawl.tools.checkstyle.filters.utils; | ||
|
|
| import com.puppycrawl.tools.checkstyle.api.AuditEvent; | ||
| import com.puppycrawl.tools.checkstyle.api.Filter; | ||
|
|
||
| public final class FileRemovalFilter implements Filter { |
There was a problem hiding this comment.
FileRemovalAfterFirstUsageFilter
|
|
||
| public final class FileRemovalFilter implements Filter { | ||
|
|
||
| private final AtomicInteger violationCount = new AtomicInteger(0); |
| final int currentCount = violationCount.incrementAndGet(); | ||
|
|
||
| boolean result = true; | ||
| if (currentCount == 2) { |
| targetFilter, tempInputFile.getPath()); | ||
|
|
||
| final AuditEvent dummyEvent1 = buildDummyAuditEvent(tempInputFile.getPath()); | ||
| final AuditEvent dummyEvent2 = buildDummyAuditEvent(tempInputFile.getPath()); |
There was a problem hiding this comment.
Nothing dummy.
Please use Input file.
b3d5fad to
26bfe8e
Compare
romani
left a comment
There was a problem hiding this comment.
please always reply to each review item as "done" or any disagreement or comments.
it help a lot.
| final AuditEvent auditEvent1 = new AuditEvent( | ||
| tempInputFile.getPath(), tempInputFile.getPath(), | ||
| new Violation(1, null, null, null, null, Object.class, null)); | ||
| targetFilter.accept(auditEvent1); |
There was a problem hiding this comment.
one more time: test method should use Input files with config inside of it.
2d5bfc1#diff-0aa5d4351017b80ba94f82da4e00e2396e2db8a811918444878635c740400263R1401
test should use verifyWithInlineConfigParser method only.
location to register test module - 2d5bfc1#diff-e7b107f6c9570fd3f500483f55b8bfb863cae9c96384f286d9a50be3ed4b725fR61
example of Input file 2d5bfc1#diff-fa96fe0c65d2dd977a14acfbd8d38cebb470c9b1fff52d19e22801b2d833120dR4
|
@akankshat05, ping. |
|
we lost connection to contributor |
|
@romani i have question about your statment
is that actually true in |
|
Looks like not:), thanks for pointing on this. |
with set that solution will not work what about using LinkedHashSet it will not change alot but we can ensure the order |
|
Please create new PR, let's discuss it from scratch |
i am trying to solve problem with LinkedhashSet and verifyWithInlineXmlConfig to make working pr to discuss the issue but i have several problem |
|
Please create PR with what you have, and we will discuss and more clearly understand problems |
For #14019
Removed suppressions:
Steps followed to kill mutation
pitest-filters-suppressions.xmlgroovy .ci/pitest-survival-check-xml.groovy --listusing java 11 and groovy 2.4.5pitest-filtersas active profilemvn -e --no-transfer-progress -P"$PITEST_PROFILE" clean test-compile org.pitest:pitest-maven:mutationCoveragegroovy .ci/pitest-survival-check-xml.groovy "$PITEST_PROFILE".Response:
No new surviving mutation(s) found.