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
I expect the spy object to return the real property value of an entity. In this case, the id property of SimpleEntity should return 1L as explicitly set in the test setup.
Current Behavior
Instead of returning the real value, the spy object returns 0, which seems to be a default primitive type value. This behavior is inconsistent with my understanding of how spyk should function.
Context
MockK version: 1.13.8
Operating System: Mac M1 Max (Sonoma 14.2.1)
Kotlin version: 1.5.20
JDK version: 11
Type of test: Unit test
JUnit version is not relevant in this context.
Minimal Reproducible Code
Here is a minimal code snippet to reproduce the issue:
importjavax.persistence.Entityimportjavax.persistence.GeneratedValueimportjavax.persistence.GenerationTypeimportjavax.persistence.Id
@Entity
classSimpleEntity (
@Id @GeneratedValue(strategy =GenerationType.IDENTITY) valid:Long,
)
importorg.springframework.data.jpa.repository.JpaRepositoryinterfaceSimpleEntityRepository: JpaRepository<SimpleEntity, Long>
// Test CodeclassExampleTest : StringSpec({
"exampleTest" {
val simple = spyk(SimpleEntity(id = 1L))
every {
simpleEntityRepository.findById(simple.id).orElseThrow()
} returns simple
// Expecting id to be 1L, but the id in the 'every' block is 0
}
})
I would appreciate any insights or suggestions on why this behavior occurs and how to resolve it.
The text was updated successfully, but these errors were encountered:
Expected Behavior
I expect the spy object to return the real property value of an entity. In this case, the id property of SimpleEntity should return 1L as explicitly set in the test setup.
Current Behavior
Instead of returning the real value, the spy object returns 0, which seems to be a default primitive type value. This behavior is inconsistent with my understanding of how spyk should function.
Context
MockK version: 1.13.8
Operating System: Mac M1 Max (Sonoma 14.2.1)
Kotlin version: 1.5.20
JDK version: 11
Type of test: Unit test
JUnit version is not relevant in this context.
Minimal Reproducible Code
Here is a minimal code snippet to reproduce the issue:
I would appreciate any insights or suggestions on why this behavior occurs and how to resolve it.
The text was updated successfully, but these errors were encountered: