Skip to content

Conversation

cgm-aw
Copy link
Contributor

@cgm-aw cgm-aw commented Feb 17, 2025

Hi,

as mentioned in #1291, if setting a backing field fails, it just prints a warning but the test does not fail. I introduced a new parameter to alter this behavior - when the new property is set to true, the test fails.
I think this improves handling a lot, as clearly the developer wanted to mock something which failed.
The parameters are a bit confusing to me, as there is the io/mockk/settings.properties and the mockk.properties file. I used settings.properties because it is available in the code I added the fix to. The property "throwExceptionOnBadMock" sounds like it should do what I implemented, but I did not want to break existing codebases by re-using this property.
The unit tests are not very nice, the real problem occurs if you mix Java and Kotlin code (see the original issue) and Java files are not available on the classpath in the current setup of MockK.

Please check it out, I would be happy if this change made it :)

@Raibaz
Copy link
Collaborator

Raibaz commented Feb 24, 2025

Thanks for looking into this!

Overall the PR looks good to me.

Could you also add the documentation about the new configuration flag, please?

Thanks!

@cgm-aw
Copy link
Contributor Author

cgm-aw commented Feb 24, 2025

Hi,

sure, please check the change: 280047b

Best regards

@Raibaz Raibaz merged commit e32dcd7 into mockk:master Feb 24, 2025
22 checks passed
SaintPatrck added a commit to bitwarden/android that referenced this pull request 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 [#&#8203;1073](https://redirect.github.com/mockk/mockk/issues/1073)): Bug fix for the issue with mocking value classes with coEvery by [@&#8203;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 [@&#8203;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 [@&#8203;kpadhiamex](https://redirect.github.com/kpadhiamex) in [https://github.com/mockk/mockk/pull/1331](https://redirect.github.com/mockk/mockk/pull/1331)

##### New Contributors

-   [@&#8203;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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants