Skip to content
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

Test passes when compiled for JDK target 19, but fails when compiled for JDK target 21 #1194

Open
3 tasks done
pedro-carneiro opened this issue Dec 27, 2023 · 3 comments
Open
3 tasks done

Comments

@pedro-carneiro
Copy link

Prerequisites

  • 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

Test passes.

Current Behavior

Test fails.

Failure Information (for bugs)

Test fails with io.mockk.MockKException: Missing calls inside verify { ... } block. when compiled for JDK target version 21.

But it passes if compiled for JDK target version 19.

Steps to Reproduce

  1. Use the code example at the end of the description
  2. Make sure it is compiled for JDK target version 21
  3. Run the test, and it fails

Context

  • MockK version: 1.13.8
  • OS: MacOS 14.2.1
  • Kotlin version: 1.9.21
  • JDK version: 21.0.1
  • JUnit version: 5.8.2
  • Type of test: unit test

Stack trace

io.mockk.MockKException: Missing calls inside verify { ... } block.

	at io.mockk.impl.recording.states.VerifyingState.checkMissingCalls(VerifyingState.kt:52)
	at io.mockk.impl.recording.states.VerifyingState.recordingDone(VerifyingState.kt:21)
	at io.mockk.impl.recording.CommonCallRecorder.done(CommonCallRecorder.kt:47)
	at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:63)
	at io.mockk.impl.eval.VerifyBlockEvaluator.verify(VerifyBlockEvaluator.kt:30)
	at io.mockk.MockKDsl.internalVerify(API.kt:120)
	at io.mockk.MockKKt.verify(MockK.kt:218)
	at io.mockk.MockKKt.verify$default(MockK.kt:209)

Minimal reproducible code (the gist of this issue)

import io.mockk.spyk
import io.mockk.verify
import org.junit.jupiter.api.Test

class TestClass {
    private data class SuchClass(
        val suchAttribute: String,
    )

    @Test
    fun test() {
        val s = SuchClass(suchAttribute = "string")
        val spy = spyk<SuchClass>(s)

        spy.suchAttribute

        verify(exactly = 1) { spy.suchAttribute }
    }
}
@benjamineckstein
Copy link

any update on this issue? I am facing exactly the same problem

@ddaakk
Copy link

ddaakk commented Feb 22, 2024

I have correctly set up all versions to reproduce, and the tests pass successfully. Could you provide a project that can reproduce?

@vmartyniuk107
Copy link

I have the same problem with static classes. For ex:

mockkStatic(UUID::class)
every { UUID.randomUUID() } returns fakeUuid

io.mockk.MockKException: Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock

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

No branches or pull requests

4 participants