Skip to content

docs(readme): document suppressing superclass calls - #1444

Merged
Raibaz merged 2 commits into
mockk:masterfrom
ch200203:docs/add-guide-suppressing
Nov 1, 2025
Merged

Raibaz merged 2 commits into
mockk:masterfrom
ch200203:docs/add-guide-suppressing

Conversation

@ch200203

Copy link
Copy Markdown
Contributor

Summary

Added a short guide to the Features section of the README explaining
how to suppress superclass method calls using existing MockK features (spyk + every { ... } just runs).

This provides a simple, built-in alternative to PowerMockito’s suppress functionality,
showing how to isolate subclass logic during testing without executing unwanted parent behavior.


Motivation

Users migrating from PowerMockito or testing complex class hierarchies (such as framework base classes)
often look for a way to “suppress” super method calls.
MockK already supports this pattern, but it was not explicitly documented.

Adding this example improves discoverability and helps users understand how to achieve
the same behavior using spyk and explicit stubbing.


Changes

  • Updated README.md
    • Added a new subsection “Suppressing superclass calls” under Features
    • Included an example using a simple Parent / Child class hierarchy
      demonstrating suppression via every { ... } just runs
    • Added a short explanation for users coming from PowerMockito

Notes

Comment thread README.md Outdated
assertFalse(child.superCalled)
```

This approach allows you to isolate the logic within your method for unit testing without executing unwanted parent class behavior

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing the full stop at the end of the sentence :)

Comment thread README.md
To suppress a method call, especially a `super` call inside an overridden method, you can stub its behavior on a `spyk`.
Using `every { ... } just runs` replaces the entire method body, preventing the original code from executing.

This is particularly useful for users coming from frameworks like PowerMockito or for testing classes like Android Activities.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding a link to the documentation for PowerMockito's suppress here? (https://github.com/powermock/powermock/wiki/Suppress-Unwanted-Behavior)

@ch200203

Copy link
Copy Markdown
Contributor Author

Thanks @Raibaz! 🙏
Added the full stop and PowerMockito suppress link as suggested
Let me know if everything looks good now.

@Raibaz
Raibaz merged commit 9fd0440 into mockk:master Nov 1, 2025
22 checks passed
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

Successfully merging this pull request may close these issues.

2 participants