Questions tagged [mockk]

Mockk is a free, open source mocking framework for Kotlin programming language. With some features similar to Mockito and Powermock, Mockk enables Kotlin developers to mock Kotlin features with a simple DSL, allowing for simple and concise testing code.

Mockk is a Mocking library that enables developers to test their code with a simple DSL. With familiar features from and , Mockk enables developers to test their / code in a simple but powerful fashion.

val car = mockk<Car>()

every { car.drive(Direction.NORTH) } returns Outcome.OK

car.drive(Direction.NORTH) // returns OK

verify { car.drive(Direction.NORTH) }
521 questions
0
votes
1 answer

Calling a function of a spyk'd data class

I have a data class A with a function as follows: data class A(val a: String) { fun foo(b: String) = "$a, $b" } I attempt the following mock in my test: fun `whatever`() { val spy = spyk() every { spy.a } returns "Tree" …
Alwyn Schoeman
  • 467
  • 7
  • 13
0
votes
2 answers

How to achive @Capturing like behavior in MockK?

We have Spring application unit tested using JMockit mock framework. Now we would like to write new tests in Kotlin using MockK. Almost everything seems to work fine but we can't figure out how to mock beans autowired by Spring. With JMockit we used…
Klugi
  • 11
  • 2
0
votes
1 answer

Is it possible to keep the already existent implementations of an interface?

I have an interface like this: interface Database { fun insertItems(items: List) fun deleteItems(items: List) fun runTransaction(alsoDelete: Boolean) { insertItems(listOf(ItemData(id = 1), ItemData(id = 2),…
gesuwall
  • 587
  • 2
  • 5
  • 15
0
votes
1 answer

How should an inline function on a Kotlin class be imported

There is a kotlin file in a project dependency jar (called, for example, KotlinClass) with an inline function package io.pack inline fun every(){ ///does stuff } If I import it into a Java class as a static: import static…
Jason Harris
  • 53
  • 2
  • 9
0
votes
1 answer

Which dependencies are required to import `io.mockk.every` when writing Kotlin tests with Mockk?

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…
Jason Harris
  • 53
  • 2
  • 9
-1
votes
1 answer

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

Mockk Error in android Koltin Unit test. matching with Two URL io.mockk.MockKException: Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock @Before fun setUp() { mockkStatic(Uri::class) …
Android Dev
  • 421
  • 8
  • 26
-1
votes
1 answer

How to mock object creation inside a class in MockK using Kotlin?

I have an aws lambda function as below: class FooHandler: RequestHandler { private val lambdaClient = LambdaClient.create() private val logger =…
CyberPunk
  • 1,297
  • 5
  • 18
  • 35
-1
votes
1 answer

update Android studio Electric eel, the mockk spyK is failing

Same code using with Android studio Dolphin, it works fine, but after update the Android Studio Electric Eel | 2022.1.1 Patch 1, it starts to fail. @Test fun test_connection() { val url = URL("http://www.google.com") try…
lannyf
  • 9,865
  • 12
  • 70
  • 152
-1
votes
1 answer

How to setup Mockk for an Android project

I added the mock dependecy to the build.gradle: testImplementation "io.mockk:mockk:1.13.2" testImplementation "io.mockk:mockk-agent-jvm:1.13.2" Now I want to use the import: io.mockk.* This dosen't work and android studio says: Unresolved…
-1
votes
1 answer

Getting error while writing test cases for amazonSNS.publish()

Src Code class ReportingUtil { companion object { private val gson = Gson() private val amazonSNS = AmazonSNSClientBuilder.standard().build() private val topicArn = AppConfig.findString(TOPIC_ARN) } /** *…
Akash Patel
  • 189
  • 1
  • 5
  • 13
-2
votes
1 answer

mockk a global property in kotlin

I am facing the same issue as asked in the below question. please help me out. Mock a "global" property in Kotlin I tried solution provided in above question but nothing is working. and I am asking the same question because I am not able to post any…
Jitendra
  • 37
  • 2
  • 7
1 2 3
34
35