-
-
Notifications
You must be signed in to change notification settings - Fork 366
Throw a warning when mocking classes that should not be mocked #1304
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
Comments
Hello! |
Sure, go ahead! |
Hi @Raibaz , I would like to work on this, can you please assign this to me? |
@MahmoudMabrok, no, you're right, this feature is meant exactly to prevent issues like #603 from being opened. |
Raibaz
added a commit
that referenced
this issue
Feb 11, 2025
…classes [#1304] feat: Restrict mocking of certain classes and add configuration option
SaintPatrck
added a commit
to bitwarden/android
that ref
9B0D
erenced
this issue
Mar 4, 2025
Update mockk from 1.13.13 to 1.13.17 <details> <summary>mockk/mockk (io.mockk:mockk)</summary> ### p`v1.13.17`](https://redirect.github.com/mockk/mockk/releases/tag/1.13.17) [Compare Source](mockk/mockk@1.13.16...1.13.17) ##### What's Changed - Fix(Issue #1333): Bug fix for the issue with MockK 1.13.16 Wraps Results Objects Twice by @kpadhiamex in [#1334](mockk/mockk#1334) - Fix (issue# 1329) parallel testing for unmockkAll by @kpadhiamex in [#1335](mockk/mockk#1335) - [[#1304]](mockk/mockk#1304) feat: Restrict mocking of certain classes and add configuration option by @devtaebong in [#1340](mockk/mockk#1340 - Update README.md - Clarify that private fields cannot be mocked by @p4ulor in [#1347](mockk/mockk#1347) - Added new property "failOnSetBackingFieldException" to fail test if a backing field could not be set by @cgm-aw in [#1349](mockk/mockk#1349) - Fix compilation error in constructedWith docs by @TWiStErRob in [#1354](mockk/mockk#1354) **Full Changelog: **Full Changelog**: mockk/mockk@1.13.16...1.13.17 ### [`v1.13.16`](https://redirect.github.com/mockk/mockk/releases/tag/1.13.16) [Compare Source](https://redirect.github.com/mockk/mockk/compare/1.13.14...1.13.16) ##### What's Changed - Fix( Issue [#​1073](https://redirect.github.com/mockk/mockk/issues/1073)): Bug fix for the issue with mocking value classes with coEvery by [@​kpadhiamex](https://redirect.github.com/kpadhiamex) in [https://github.com/mockk/mockk/pull/1332](https://redirect.github.com/mockk/mockk/pull/1332) **Full Changelog**: mockk/mockk@1.13.14...1.13.16 ### [`v1.13.14`](https://redirect.github.com/mockk/mockk/releases/tag/1.13.14) [Compare Source](https://redirect.github.com/mockk/mockk/compare/1.13.13...1.13.14) ##### What's Changed - fix(1308): Handle nullable complex and nested value classes by [@​VasilisDrettas-tomtom](https://redirect.github.com/VasilisDrettas-tomtom) in [https://github.com/mockk/mockk/pull/1314](https://redirect.github.com/mockk/mockk/pull/1314) - Fix(Issue no. 1330) for Relaxed Mocking Value When Property is Nested Value Class by [@​kpadhiamex](https://redirect.github.com/kpadhiamex) in [https://github.com/mockk/mockk/pull/1331](https://redirect.github.com/mockk/mockk/pull/1331) ##### New Contributors - [@​kpadhiamex](https://redirect.github.com/kpadhiamex) made their first contribution in [https://github.com/mockk/mockk/pull/1331](https://redirect.github.com/mockk/mockk/pull/1331) **Full Changelog**: mockk/mockk@1.13.13...1.13.14 </details>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are a few classes that it is generally a bad idea to mock: trying to mock them is usually a code smell indicating that a test is not testing the correct part of the application, and mocking them usually leads to problems.
Some of these are:
System
HashMap
)File
orPath
(you should be wrapping them in a layer that only deals with I/O rather than mixing it with business logic)Mockk should at least log a warning when trying to mock one of these classes, but ideally it should also have a configuration flag that disables mocking them altogether and has it throw an exception when a user tries to.
We could maybe even make the list of non-mockable classes configurable.
The text was updated successfully, but these errors were encountered: