I have imported mockk
library in commonTest
-> shared
module. There are no import errors in the test classes, but when I run the test I get errors like:
Unresolved reference: every
Unresolved reference: mockk
Unresolved reference: verify
in all places where i use mock
library methods. What could be the reason for the errors?
example of my test with errors in console:
class DefaultAppPreferenceStorageTest {
val appPreference = mockk<AppPreference>() //Unresolved reference: mockk
val jsonService = mockk<JsonService>() //Unresolved reference: mockk
val jsonKey = "key"
val value = 1
val stringValue = "$value"
val defaultIntValue = Random.nextInt()
val storage = DefaultAppPreferenceStorage(
appPreference,
jsonService
)
inner class PutJsonTest {
@BeforeTest
fun beforeEachTest() {
every { jsonService.mapToString(value) } returns stringValue //Unresolved reference: every
storage.putJson(jsonKey, value)
}
@Test
fun testPutJson() {
verify(verifyBlock = { jsonService.mapToString(value) }) //Unresolved reference: verify
verify(verifyBlock = { appPreference.putString(jsonKey, stringValue) }) //Unresolved reference: verify
}
}
...
}
UPDATE Dependencies
const val mockk = "1.12.5"
const val mockk = "io.mockk:mockk-common:${Version.mockk}"
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation(ShareTestDependencies.mockk)
implementation(ShareTestDependencies.coroutinesTest)
}
}