0

I'm trying to write a test based on just testCompile group: 'io.mockk', name: 'mockk', version: '1.7.15' but in the code below:

import io.mockk.every
import io.mockk.any
import io.mockk.Runs
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension

@ExtendWith(MockKExtension::class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
internal class ConfigDistributorTest {
        @MockK
        lateinit var configService: ...

        @MockK
        lateinit var centralisedConfigRegisterService: ...

            val configDistributor =  ConfigDistributor(centralisedConfigRegisterService, configService)

            @Test
            fun shouldDistributeConfigToComponents(){
                every {
                    configService.readConfig(any())
                } just Runs
            }
        }

although Runs, MockK and MockKExtension are successfully imported, the every and any() are not available. Is io.mockk.any the correct import statement and which other dependency is required to use them?

1 Answer 1

3

First you need to import every. import io.mockk.every is the correct way to do it. Inside of every any is automatically imported, so you don't need to do that. Other things looks fine

Please invalidates caches, re-import project. Probably you have some issues with IDE.

4
  • We're using bazel.build as our build system and its our own project I'm trying to use io.mock in. It's possible that we're not adding the right jars to the classpath. Could you confirm that we only need mockk-1.7.15.jar, mockk-dsl-jvm-1.7.15.jar and mockk-agent-1.7.15.jar on the classpath ? Apr 21, 2018 at 6:51
  • 1
    I can confirm that this is what I have in Gradle. +dependency kotlin-reflect
    – oleksiyp
    Apr 22, 2018 at 8:11
  • Thanks: it look like its some strange Intellij/Kotlin situation: in a java class, import static io.mockk.MockKKt.every; is fine! Apr 22, 2018 at 10:08
  • Its sorted out now, thanks. It was an issue with how Kotlin dependencies are setup by Bazel. I'll be able to start using io.mockk properly now! Apr 23, 2018 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.