i am trying to make a simple unit test for a couple of simple methods but this is my first try with mockito so i don’t really understand what am i doing wrong. Here’s the class that i want to test object AppPreferenceHelper { private var sharedPreferences: SharedPreferences? = null fun initPreferences(context: Context) { sharedPreferences ..
Category : mockito-kotlin
I’m kinda new to doing a unit test for my android application. I’ve read some documentation, but still didn’t figure out how to test my "Presenter" class. Is there any solution or perhaps samples for unit testing in android with MVP architecture? especially related to firestore cloud. My Presenter class looks like this: class MainPresenter(val ..
This is my testing class: class RocketListVMTest { @get:Rule var instantTaskExecutorRule = InstantTaskExecutorRule() private lateinit var sut: RocketListVM private var activeOnlyToggle = false private val repo: Repo = mock() @Before fun setUp() { sut = RocketListVM(repo) activeOnlyToggle = false } @Test fun toggleActiveOnlyWithTrueCallsRepository() { sut.toggleActiveOnly(true) verify(repo).getActiveOnlyLocalRockets() } } With the following dependencies: androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0" androidTestImplementation ..
I’m using Mockito for unit testing. I want to test my usecase and with mock repository but there’s some problem. I had my repository’s function returns arraylist by using mockito. (here’s code below) `when`(mockRepository.searchByKeyword(request.auth, request.keyword)).thenReturn(myArrayList) And created usecase with the mock repository. (here’s code below too) val useCase = SearchProjectUseCase( mockRepository, coroutineRule.testDispatcher ) SearchUseCase’s code ..
On the way of learning unit test with mockK I came across with this scenario: MyViewModel: private val _spinner: MutableLiveData<Boolean> = MutableLiveData() val getSpinner : LiveData<Boolean> get() = _spinner fun launchCoruotine() { viewModelScope.launch { repository.refreshTitle() _spinner.value = true } } dummy repository: suspend fun refreshTitle() { delay(4000) } How do I write unit test for ..
I am moving some unit test code to use MockitoKotlin from Mockito and in Mockito kotlin how can i pass a classObject as a parameter for any(). This is my Mockito code which uses Argument matcher Mockito.`when`(serviceOrderApi.serviceOrderStandUpdate(ArgumentMatchers.anyString(), ArgumentMatchers.any(StandUpdateRequest::class.java))).thenReturn(Observable.just(serviceOrder)) I wanted to change it to use Mockito Kotlin library which is com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0 and I changed the ..
kotlin library for both test and android tests, unit tests and UI tests. If I write the bellow two lines as part of build.gradle it works fine. my question is, is this the right way to add the library to use in both test and android tests build.gradle androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0" testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0" Thank you for ..
I have a function I wish to test called withCredentials which I use to pass the required arguments needed to make an API call with the user’s credentials , it looks something like this: @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) internal suspend fun <T> withCredentials(block: suspend (String) -> Response<T>): ServiceResponse<T> its responsibility is to fill in the authentication ..
Please help how do I solve this error: no native-lib in java.library.path kotlin.KotlinNullPointerException at com.axis.net.helper.Application$Companion.getCacheDirectory(Application.kt:42) at com.axis.net.dagger.modules.modules.ApiModule.<init>(ApiModule.kt:150) at com.axis.net.dagger.componens.DaggerViewModelComponent$Builder.build(DaggerViewModelComponent.java:581) at com.axis.net.ui.splashLogin.viewModel.AutoLoginViewModel.<init>(AutoLoginViewModel.kt:60) at com.axis.net.ui.splashLogin.viewModel.AutoLoginViewModel.<init>(AutoLoginViewModel.kt:33) at com.axis.net.autoLogin.AutoLoginViewModelTest.<init>(AutoLoginViewModelTest.kt:47) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217) at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) I’m using mockito library for testing, but ..
I am trying to create a unit test using Spek framework and nhaarman mockito kotlin in my Android Kotlin project. The problem is that when there is nested suspend method I don’t know how to mock response.This is how I’m trying I defined: val testCoroutineDispatcher = TestCoroutineDispatcher() val testCoroutineScope = TestCoroutineScope(testCoroutineDispatcher) and before any describe ..
Recent Comments