mockk Questions

2

Within our Android app we are using Google Maps API in order to show the users location. At the moment we are using Koin in order to provide a parametered injection (it requires an activity) of the...
Ridenour asked 16/7, 2019 at 8:45

11

Solved

I'm stuck trying to mock some stuff with mockk: I have the following setup on gradle root: |-- App (just a sample app for the SDK) |-- SDK (SDK we develop) << apply plugin: 'com.android.l...
Mandarin asked 20/11, 2018 at 11:4

3

I read document, but I don't still get it. The differences between this private val myClass: MyClass = mockk(relaxed = true) and this. private val myClass: MyClass = mockk() What I understood is ...
Tribromoethanol asked 4/8, 2022 at 9:53

1

As it seems, Mockk mocks only store the reference to the received arguments for later verification. This poses a problem as soon as the argument becomes modified throughout the test. How could one ...
Admix asked 13/11, 2020 at 10:48

2

I need to verify if bar function is called or not using MockK library. MyFile.kt fun foo() { bar() } private fun bar() { ... } How can I mock the 'bar' function? I am trying the following. @Test...
Blunge asked 19/2, 2021 at 10:15

2

Solved

Mockk added support for mocking global functions. However, when they have overloads there's a problem. For example if you try to mock delay() with mockkStatic(::delay) you encounter this error: Ove...
Preceding asked 16/8, 2022 at 9:44

4

Solved

I create a mock of a class with mockk. On this mock I now call a method that gets a lambda as a parameter. This lambda serves as a callback to deliver state changes of the callback to the caller...
Paganini asked 7/12, 2018 at 16:20

2

PS: Code will be in Koltin For example, I have my service class that does something and injects some other service. class MyService( private val someOtherService: OtherService ) { fun doSometh...
Diphosgene asked 14/10, 2019 at 10:21

4

Solved

So I have the following code: When("SMS with location update command is received") { every { context.getString(R.string.location_sms, any(), any(), any(), any()) } returns "loc" mainServiceVie...
Horacehoracio asked 22/12, 2019 at 7:1

2

Solved

I need to check if a method was not invoked in my unit tests. This is an example test I did that checks if the method was invoked and it works perfectly fine: @Test fun viewModel_selectDifferentFil...
Thrift asked 30/3, 2022 at 16:23

3

Solved

Hey I am getting this kind of weird issue. I don't understand why this is causing in my unit test. Can someone please guide me what is missing in my side. Exception in thread "Test worker&quot...
Lamelliform asked 26/1, 2022 at 14:7

2

Solved

I am new in JUnit testing on Android and I'm testing a function, which is using android context object to get a string resources and making some comparsions. How can I mock android context object t...
Cambrel asked 9/9, 2019 at 10:25

2

Solved

I'm running a unit test using mockk. When trying to verify a method, I'm getting an assertionError and I can't figure out how to get the test to run. Here is my test method: @get:Rule var rule: T...
Irreclaimable asked 1/5, 2020 at 13:19

2

I've noticed that sometimes verify fails with "... call to ... happened, but arguments are not matching" Here is a sample test that shows verify failing: class TestStuff { val stuff = "1" @Re...
Anne asked 21/2, 2018 at 15:8

3

How can I mock Build.VERSION.SDK_INT in mockk? I've done the following: @Test fun testFoo(){ mockkStatic(Build::class) mockkStatic(Build.VERSION::class) every { Build.VERSION.SDK_INT } answe...
Pomelo asked 24/1, 2019 at 23:11

1

Solved

I got some code which I want to test using MockK as a mocking library: fun loadImage(imageLoader: coil.ImageLoader) { val request = ImageRequest.Builder(imageView.context) .data(url) .crossfade(...
Hessite asked 9/5, 2021 at 19:58

3

I have a simple class with a private field. class EmployeeData { private var employeeAge: Int = 0 fun getAge(): Int { return 1 + employeeAge } } I am trying to test this private employeeAge...
Percept asked 13/5, 2020 at 22:50

7

Solved

We are currently working with java with kotlin project, slowly migrating the whole code to the latter. Is it possible to mock static methods like Uri.parse() using Mockk? How would the sample cod...
Resignation asked 10/4, 2018 at 20:31

4

Lets say we have a class like this: class Whatever { private var something = false fun aMethod(): Int { return if( something ) { 1 } else { 0 } } } According to the documentation, it lo...
Childbirth asked 13/7, 2018 at 0:19

2

With mockk, to mock constructors, we can do something like (taken from documentation): class MockCls { fun add(a: Int, b: Int) = a + b } mockkConstructor(MockCls::class) every { anyConstructed&...
Haydon asked 23/12, 2018 at 10:44

2

I am getting a error when trying to use MockK in UI test which was perfectly working in Unittest cases MockK could not self-attach a jvmti agent to the current VM Full error report Caused by: io.m...
Roan asked 28/7, 2022 at 2:13

4

Solved

I know that in order to mock how a method responds, you have to use every { instanceX.methodB() } returns "42" I'm trying to mock an iterator, for which you have to mock 2 methods hasNext() and...
Urissa asked 14/9, 2018 at 5:4

1

Solved

I am trying to verify that a function was not called using the following: verify { managementService.deleteUser(any()) wasNot Called } That verification fails with the message: Verification fail...
Esquire asked 5/1, 2023 at 23:1

5

Solved

We had a few tests in Java and Mockito, which we are progressively converting into Kotlin and Mockk. There's a problem, though. This simple line: verify(mockedInteractor).setIndex(1); When we mov...
Xylon asked 14/5, 2020 at 15:27

2

Solved

When I just want to test a method is called in other method, how can I do that? I don't want the method runs after it is called. fun aMethod(){ bMethod() } fun bMethod(){ // complex } I tried ...
Meyerhof asked 2/8, 2022 at 6:57

© 2022 - 2025 — McMap. All rights reserved.