You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please answer the following questions for yourself before submitting an issue.
I am running the latest version
I checked the documentation and found no answer
I checked to make sure that this issue has not already been filed
Expected Behavior
When spying on mock classes I want to have access to the private properties of the Parent class. And that those properties doesn't need to be lazy initialized in order to work as a mock.
Current Behavior
The test fails with the message can't find property hashMap for dynamic property get. Also, there's a problem with the private properties that are not mocked if they are static-initialized. They only work if they are lazy initialized. (Relates to #263)
Context
Relates to this Issue #425 which was fixed in this PR #785
I think the fix for the properties will be similar as the one for functions.
MockK version: 1.13.5
OS: Android 13
Kotlin version: 1.8.10
JDK version: 11
JUnit version: 4
Type of test: Unit Test
Stack trace
can't find property hashMap for dynamic property get
io.mockk.MockKException: can't find property hashMap for dynamic property get
at app//io.mockk.InternalPlatformDsl.dynamicGet(InternalPlatformDsl.kt:159)
at app//io.mockk.MockKMatcherScope.getProperty(API.kt:2065)
at app//[app.package].MockkPrivatePropertyTest$should put a value in the map when the value doesn't exists in it$1.invoke(MockkPrivatePropertyTest.kt:17)
at app//[app.package].MockkPrivatePropertyTest$should put a value in the map when the value doesn't exists in it$1.invoke(MockkPrivatePropertyTest.kt:17)
at app//io.mockk.impl.eval.RecordedBlockEvaluator$record$block$1.invoke(RecordedBlockEvaluator.kt:25)
at app//io.mockk.impl.eval.RecordedBlockEvaluator$enhanceWithRethrow$1.invoke(RecordedBlockEvaluator.kt:78)
at app//io.mockk.impl.recording.JvmAutoHinter.autoHint(JvmAutoHinter.kt:23)
at app//io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:40)
at app//io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:30)
at app//io.mockk.MockKDsl.internalEvery(API.kt:94)
at app//io.mockk.MockKKt.every(MockK.kt:143)
Minimal reproducible code (the gist of this issue)
classMockkPrivatePropertyTest {
privateval classUnderTest = spyk(ChildCls(), recordPrivateCalls =true)
privateval mockMap:MutableMap<String, String> = mockk(relaxed =true)
@Test
fun`should put a value in the map when the value doesn't exist in it`(){
// Given
every { classUnderTest getProperty "hashMap" } returns mockMap
// When
classUnderTest.checkAndUpdate("key", "value")
// Then
verify(exactly =1) { mockMap[any()] }
verify(exactly =1) { mockMap[any()] = any() }
}
}
abstractclassParentCls {
privateval hashMap:MutableMap<String, String> =mutableMapOf()
funcheckAndUpdate(key:String, value:String) {
if (hashMap[key] ==null) {
hashMap[key] = value
}
}
}
classChildCls: ParentCls() {
fundoSomethingElse() =Unit
}
The text was updated successfully, but these errors were encountered:
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Expected Behavior
When spying on mock classes I want to have access to the private properties of the Parent class. And that those properties doesn't need to be lazy initialized in order to work as a mock.
Current Behavior
The test fails with the message
can't find property hashMap for dynamic property get
. Also, there's a problem with the private properties that are not mocked if they are static-initialized. They only work if they are lazy initialized. (Relates to #263)Context
Relates to this Issue #425 which was fixed in this PR #785
I think the fix for the properties will be similar as the one for functions.
Stack trace
Minimal reproducible code (the gist of this issue)
The text was updated successfully, but these errors were encountered: