fix: prevent confirmVerified(vararg mocks) from clearing unrelated mocks
🚧 Draft Pull Request – Partial Fix for Issue #1379
This PR builds upon the changes introduced in #821, aiming to improve test isolation while addressing the regression reported in #1379.
🛠 What's Being Done
- Refactored
internalConfirmVerifiedto reset only the specified mocks when parameters are passed. - Updated
resetVerificationStateto selectively clear verification state for specific mocks. - Ensured cleanup with
try-finally, making the verification process more robust. - Added a test case
confirmVerifiedSpecificMockto verify thatconfirmVerified(mock)behavior is correct.
⚠️ Current Status
This PR is still in progress. While the targeted clearing works in isolated tests, the test suite fails when running confirmVerifiedAll.
This issue appears similar to the cross-test interference previously addressed in issue #821, but now occurs when confirmVerified is used without parameters after using it with specific mocks in other tests.
👉 Notably, if we add a clearAllMocks() call before the confirmVerifiedAll test, it passes successfully — just like it did before PR #1367.
🔍 Next Steps
Investigate and resolve the failure of confirmVerifiedAll in the full test suite
@Raibaz do you have any idea why this might be happening? It seems related to state retention when mixing confirmVerified(mock) and confirmVerified() in different tests.
Wild guess: could it be that verify with more than one call, such as the one in the confirmVerifiedAll test, don't add the right values to the list of verified calls?
Can you check the values of allCalls and verifiedCalls here, when your test fails?
Wild guess: could it be that
verifywith more than one call, such as the one in theconfirmVerifiedAlltest, don't add the right values to the list of verified calls?
I don’t think that’s the root cause, because when the confirmVerifiedAll test is run in isolation, it passes — so it seems that verify { ... } with multiple calls is working as expected in that context.
However, when the whole test suite is executed, the same test fails. That suggests some shared state leakage or interference between tests, similar to what we saw before the fix for #821.
Can you check the values of
allCallsandverifiedCallshere, when your test fails?
Yes — I added debug prints and here’s what I found during a failing run (screenshot attached below). So it looks like the verifiedCalls list gets cleared unexpectedly across tests. Interestingly, if I add a clearAllMocks() at the beginning of the confirmVerifiedAll test, it passes — just like it used to before PR #1367.
That's interesting - I'd do more investigation to understand who's clearing the verifiedCalls list, when and why :)