All Questions
328 questions
0
votes
1
answer
13
views
Unit fails - Missing mocked calls
Issue: Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock
io.mockk.MockKException: Missing mocked calls inside every { ... } block: make sure the object ...
0
votes
1
answer
129
views
Android Unit Tests - Geocoder Mockk "Failed matching mocking signature for"
I'm trying to build some unit tests and mock the Geocoder API in Android.
I have the following function which I try to build a unit test against it:
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
private ...
0
votes
1
answer
32
views
Mocking functions with every fails in Android unit tests on JWT
I have the following data class with its functions:
@JsonClass(generateAdapter = true)
data class AuthToken(
@Json(name = "token") val access: String,
@Json(name = "refreshToken&...
0
votes
0
answers
13
views
ViewModel Until test case error Provider members initialize error
I am getting provider initial error while trying to run viewModel test case
Provider members initialize error
com.venuetize.vzsportsapp.providers.Provider$ProviderException: Provider members ...
0
votes
0
answers
85
views
Need guidance on mocking data from a wearable device for Android app development with react native
I am working on react native app that encourages users to stand up and avoid prolonged periods of sitting. The app relies on data from a wearable device to track user activity. However, due to ...
1
vote
3
answers
7k
views
Mocking Static Methods - Kotlin
I've been using Mockito, Mockk and PowerMock to mock static methods, to not avail.
I'm not sure if my understanding is correct, but I was expecting that, when I mock a (static or instance) method, the ...
0
votes
0
answers
176
views
How to test a private variable inside a method using Mockito or Junit
I wish to write a test which can confirm that the private title variable will equal "internet connection lost please try again"
var title = ""
if (errorMessage.equals("...
0
votes
0
answers
892
views
Using GPS spoofing, is it possible to tell a specific app that I'm in two locations at the same time?
I have a rooted/magisk Android phone and can change the location with mock locations + fake gps app, but I would somehow like to be in two places at once. Is this possible?
Android restricts the use ...
2
votes
0
answers
830
views
mockk function with Flow inconsistence
I am writing an Android Unit Test for a ViewModel.
I am mocking a flow like this:
coEvery { showRepository.currentShow() } returns flowOf(
ShowWithRelations(
localShow.show,
localShow....
2
votes
0
answers
163
views
How to make an instrumentation test for a fragment that is using activityViewModels?
So my setup is that I initialize all the viewModels on MainActivity then use activityViewModels to the Fragments that don't need their own instance of the viewModels. Then I wanted to create an ...
-1
votes
1
answer
767
views
Q&A: how to mock kotlin top level extension functions in android?
It is a self 'question and answer' post to track my issue and completed research on it.
I was a looking for an option to mock WorkManager (*). It utilise LiveData and its asFlow() extension function ...
1
vote
1
answer
233
views
How (and should) I verify that an async internal method was called in State Unit Testing?
override fun getSomething(): LiveData<List<Content>> {
fakeDataSource.fetchSomethingAsync()
return contentDao.getSomething()
}
Here we have a repository method to get ...
2
votes
0
answers
467
views
How do you mock a ContentResolver for Android 33?
I want to make sure that the below method only returns what it is supposed to by writing a test for it.
internal fun getMusicFromMediaStore(contentResolver: ContentResolver): List<MusicFile>
...
4
votes
2
answers
9k
views
Mock a constructor and return a mocked object instead of real object with mockk
I have a challenge with a class which I want to test but inside the class other objects will be created.
This simple example shows the issue.
class A {
val b: B
init() {
b = B()
}
}
...
0
votes
1
answer
232
views
MockK Mocking a Surface object for Android
I'm trying to test some code, and I need a valid Surface object for Android in order to properly test it, since a lot of the code checks if there is a valid surface (ie surface.isValid() where surface ...
3
votes
2
answers
6k
views
MockK Kotlin: Verification failed: call 1 of 1: was not called
I'm trying to essentially test whether a specific method in my class calls a different method properly. I'll remove all unneeded code, so basically my code is as follows:
public class Monitor {
...
0
votes
0
answers
840
views
Mock Bluetooth device appium
I am currently testing a native mobile app using appium automation with java. Currently testing with android. In that app, I need to connect to a Bluetooth device which actually a physical device.
For ...
0
votes
1
answer
410
views
Why Do I Still Have java.lang.RuntimeException: Method setText in android.widget.Toast not mocked.?
I still have method not mocked when I clearly stated the when function from Mock. Any tips? Thank you in advance.
This is my test code that I have created to test the function.
@Test
fun ...
4
votes
1
answer
10k
views
How to mock a Retrofit Response
I'm trying to mock a Retrofit Response when it isn't successful.
interface ServiceInterface {
@POST("auth/login")
suspend fun loginRequest(@Body loginInformation: LoginInformation) : ...
0
votes
0
answers
120
views
Cannot mock BluetoothGattCharacteristic.addDescriptor method
I am trying to write a test for a method which call BluetoothGattCharacteristic.addDescriptor method. For some reason I can't mock this method in order to write a test. I am still new to the mocking ...
1
vote
0
answers
381
views
Getting NullPointerException while trying to mock view model in android instrumentation test
Here's the crash log
java.lang.NullPointerException: Null reference used for synchronization (monitor-enter)
at androidx.lifecycle.ViewModel.setTagIfAbsent(ViewModel.java:156)
at androidx....
0
votes
1
answer
306
views
Postman mock services not working on flutter android app release
I am using postman for a mock api services to test back-end requests on a flutter android app, it works in debug mode however when I create an app release it doesn't work, why is that?
1
vote
1
answer
4k
views
Android io.mockk.MockKException: no answer found for: Calendar(child of static Calendar#368).getTime()
I am writing a unit test, and I am new to this,
I was facing this error and didn't find a solution for it.
This is the complete exception log.
io.mockk.MockKException: no answer found for: Calendar(...
3
votes
1
answer
1k
views
Android test boolean method returns false every time?
I want to test method checkTextLength() of DesignInputField that returns boolean value. But it returns false every time. Tried mock library to do this. When I write this code Mockito.when(...
0
votes
0
answers
980
views
How to create mock Json API for testing android application?
I'm an android developer and I need to test my application that loads data from a JSON API but the backend is not ready yet, but I have the JSON response that I'll be using, Is there any way I can ...
0
votes
1
answer
1k
views
Android Mockito Test on View Model method with MutableLiveData
I am new to the Mockito Android Test framework and I am following MVVM architecture and I have one method in the view model which updates the live data object and I need to write test cases for that ...
0
votes
0
answers
392
views
Detect if Mock location (GPS Spoofing) is enabled and request to disable
Since I tried to make a long search about, I'm trying to detect if some app are listed to use mock location o just simply if Mock location is enabled and not setted to "anyone".
I just want ...
9
votes
1
answer
2k
views
How to mock a builder using MockK so that the builder functions are commutative?
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)
...
4
votes
1
answer
799
views
How to mock task.isSuccessful google.android.gms.tasks?
Need to mock response but for some reason does not import correctly. So how to mock that
package com.google.android.gms.tasks;
public abstract class Task<TResult> {
public Task() {
...
1
vote
1
answer
284
views
Mocked multiple times, but mocked value does not change after secondly mocked in different test method
I'm writing unit test for my ViewModel. I have mocked my data source and want to test that datasource returns success and error cases. If i run tests individually everything is OK.
In the first method ...
0
votes
1
answer
50
views
Why API actually called when run unit test of a function used Coroutine to call API with networkBoundResource in Android?
I have an issue in unit test for a function used Coroutine to call API with networkBoundResource.
The issue is when run the test the API actually called, although it's supposed to return the expected ...
0
votes
1
answer
1k
views
how to verify a parameter in unit test
I have a run function which calls repository.startFlling(orderStorage.flOrder!!.id, action) and I am trying to verify repository.startFlling is called with correct parameters.
I could mock ...
1
vote
1
answer
548
views
Mocking a final class using MockitoKotlin2
Hi I am using MockitoKotlin2 library for mocking and I am trying to mock a final class of retrofit how can I do that, does it support mocking final classes, what is the solution please.
Error
org....
3
votes
0
answers
1k
views
Mock object in activity with espresso UI test
I want to mock an object which exists in activity the object has a function which return boolean value when activity launch, this boolean value determines TextView visibility, it will be visible if ...
3
votes
1
answer
425
views
Mocking ViewModel for Espresso tests
I decided that it's time to automate some tests, and I wanted to start using Espresso. I was following few tutorials, but I am not able to make it work in my app because of my architecture.
My app is ...
6
votes
2
answers
3k
views
Test provider for mock location not working on Android 10
Mock location are not working on Android 10, crash when addTestProvider are called:
2020-11-30 00:25:16.855 13189-13256/br.com.tupinikimtecnologia.fakegpslocation E/AndroidRuntime: FATAL EXCEPTION: ...
0
votes
1
answer
195
views
espresso test: how to control the content of an intent?
I have the following code in my activity class:
@Override
public boolean onClick(View v)
{
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse(getExternalFilesDir(null))....
0
votes
1
answer
2k
views
How to Mock getSting Resource in Kotlin [closed]
I am trying to mock a resource so in my production code whenever
getString(R.string.res1)
the following data will be returned:
"aaa"
this is what I tried so far:
class Product{
fun ...
1
vote
1
answer
821
views
Mocking a suspend function asks for an extra parameter - Mockito
I am trying to mock a suspend function which accepts 3 parameters, but when I try to mock it asks for 4 parameters
suspend fun notifyBandSuspend(serviceType: String, id: String, action: TimeAction): ...
0
votes
0
answers
59
views
How to pass ArgumentMatcher correctly using Mockito
Hi in my unit test I am getting an error
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method com.xx.xxx.clean.orderview.domain.OnStandUseCaseCoroutine$Params.<init&...
9
votes
3
answers
14k
views
MockitoException when trying to mock java.lang.System
I have a test case that mock a static method of java.lang.System class:
@Test
fun `getLocalTime()`() {
// Arrange
val staticMock = Mockito.mockStatic(System::class.java)
Mockito.`when`(...
1
vote
0
answers
336
views
How to init libs in unit tests with mockito
I have a problem that when I do tests, the library that requires init gives an error that it has not been called, how can I init it in the test or mock it so that there is no error? For example now i ...
3
votes
1
answer
2k
views
How to mock super method by MockK
Assuming we have Activity.onCreate() like this
class MyActivity : AppCompatActivity() {
fun doSomething() {}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(...
7
votes
1
answer
2k
views
How to setup Mockoon for Android emulator?
I'm trying to use mockoon for running a mock API to test an Android app (using Retrofit2) on my macOS.
Using 0.0.0.0:[port] or localhost:[port] as the address doesn't work.
Any idea what I should be ...
1
vote
1
answer
1k
views
Koin test declareMock not working with multiples declaration
I am trying to declare two mocks but I am getting a java.lang.ClassCastException.
I am trying to test my MainActivity (which has a MainViewModel), so I need to mock the MainViewModel.
The thing is ...
16
votes
3
answers
3k
views
Android UI tests with Espresso + MockK crash with SIGSEGV on emulators, fine on physical devices
I have just started using MockK to mock all the Repositories / Services logic in an MVP-based app for UI tests.
I have some UI tests running a login activity where the Espresso inputs logins and ...
0
votes
2
answers
2k
views
How can i mock this method in android?
I am new to the mockito framework, Can anyone help me with how to mock this method.
@Override
public Device getCurrentDevice() {
return getDeviceById(Device.getCurrentDeviceId());
}
...
6
votes
0
answers
2k
views
How to unit test for different Build.VERSION.SDK_INT
I have found other similar questions but none of the answers were useful.
In a method I have something similar to:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// use API available ...
2
votes
1
answer
2k
views
java.lang.NoSuchMethodError: okhttp3.internal.Internal.initializeInstanceForTests() When creating a Mock Server on Android
java.lang.NoSuchMethodError: okhttp3.internal.Internal.initializeInstanceForTests() When creating a Mock Server on Android
I tried to update the dependency but it did not work.
I am new to Android ...
19
votes
2
answers
31k
views
org.mockito.exceptions.misusing.NotAMockException: Argument should be a mock, but is: class java.lang.Class for Andriod SSLContext.getInstance() metho
I am working on Android and PowerMock project. In this example, I am trying to mock the below method, but I am getting error
org.mockito.exceptions.misusing.NotAMockException: Argument should be a ...