nilTheDev
10/29/2021, 12:10 PMpackage mock
import io.mockk.mockk
internal class DummyDatabaseTest {
val mockConnection: DummyJdbiConnection = mockk()
every { mockConnection.status() } returns "This is JDBI conncetion"
}
Here is my build.gradle
file,
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.5.31'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.1'
testImplementation 'io.kotest:kotest-assertions-core:4.6.3'
testImplementation 'io.mockk:mockk:1.12.0'
}
Please see the attached screenshot to find out about the error I'm getting.
Can anyone point out where is it going wrong? Do I have to do some manual imports?Emil Kantis
10/29/2021, 12:33 PMnilTheDev
10/29/2021, 1:02 PMEmil Kantis
10/29/2021, 1:04 PMval mockConnection: DummyJdbiConnection = mockk() {
every { status() } returns "This is a JDBI connection"
}
The above will pass the mocking lambda to the mockk()
function.nilTheDev
10/29/2021, 1:08 PMevery {...} returns ...
line is actually doing. At first I thought the mockk()
function would create an instance of that object for me. So I was confused. Now I got that. It's literally mocking a function's behaviour for the mock instance. This is amazing!