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
A mock produced by spyk with an objectToCopy should be the same as if it this object is instantiated inside the spyk method itself (using a default constructor)
Current Behavior
Mocked properties are used if spyk instantiates the object itself but aren't if an instance is passed as objectToCopy and a method is called, which uses these properties internally.
Steps to Reproduce
Please provide detailed steps for reproducing the issue.
provide an objectToCopy to spyk<...>(...)
call a method, which isn't mocked but uses the mocked properties
original properties of the object are used instead of the mocked ones
Context
MockK version: 1.13.11
OS: macOS Sonoma 14.3.1
Kotlin version: 1.9.22
JDK version: 17 (Temurin)
JUnit version: /
Type of test: /
Failure Logs
Console output for code below
John
John Doe
John
Alan Turing
Minimal reproducible code (the gist of this issue)
// -----------------------[ GRADLE DEFINITIONS ] -----------------------
dependencies {
testImplementation "io.mockk:mockk:1.13.11"
}
// -----------------------[ YOUR CODE STARTS HERE ] -----------------------classPerson{
val firstName:String="Alan"val surname:String="Turing"val fullname by lazy {
"$firstName$surname"
}
}
funmain() {
val mockedPersonWorking = spyk<Person>(){
every { firstName } returns "John"
every { surname } returns "Doe"
}
println(mockedPersonWorking.firstName) // Johnprintln(mockedPersonWorking.fullname) // John Doeval mockedPersonFailing = spyk<Person>(Person()){
every { firstName } returns "John"
every { surname } returns "Doe"
}
println(mockedPersonFailing.firstName) // Johnprintln(mockedPersonFailing.fullname) // Alan Turing <---- Should be John Doe
}
// -----------------------[ YOUR CODE ENDS HERE ] -----------------------
The text was updated successfully, but these errors were encountered:
Expected Behavior
A mock produced by
spyk
with anobjectToCopy
should be the same as if it this object is instantiated inside thespyk
method itself (using a default constructor)Current Behavior
Mocked properties are used if
spyk
instantiates the object itself but aren't if an instance is passed asobjectToCopy
and a method is called, which uses these properties internally.Steps to Reproduce
Please provide detailed steps for reproducing the issue.
objectToCopy
tospyk<...>(...)
Context
Failure Logs
Console output for code below
Minimal reproducible code (the gist of this issue)
The text was updated successfully, but these errors were encountered: