Questions tagged [android-unit-testing]
61 questions
1
vote
0 answers
android unittest got instrument.IllegalClassFormatException, and why it complains "(have Java 1)."?
Having an android library project, it has been built and unit tested fine with android studio 4.1.2. Now change to use android studio (fox) 2020.3.1 path 3.
It starts to get error Cannot run gradle test tasks because of…

lannyf
- 9,865
- 12
- 70
- 152
1
vote
1 answer
Robolectric start a fragment that has an observer
How to start a fragment with a LiveData observer in the test scope with Robolectric
Fragment
class MyFragment(private val viewModel: MyViewModel) : Fragment() {
...
fun myObserver {
...
// If I remove this observer the…

Shawn
- 1,222
- 1
- 18
- 41
1
vote
0 answers
RxJava: Scheduler is null while trying to unit test an observable
I'm trying to unit test an observable in a viewmodel but I'm getting the following error. I have included the observable in question...
getRepository()
.executeGetAccount()
.doOnSubscribe(response ->…

devmike01
- 1,971
- 1
- 20
- 30
1
vote
1 answer
What should I test first with Android Clean Architecture (TDD)
I'm learning TDD with my toy project with Android Clean Architecture.
I want to know how to process my Unit Test.
I want to do TDD with my search features, in this case, Should I create my UseCase and test it first?
Or should create api client and…

HyeonSeok
- 589
- 1
- 5
- 18
1
vote
0 answers
Android Biometric unit testing
I need to write Unit test cases for Android Biometric prompt. I tried to search many links but didn't get the proper direction. Need to write unit test cases for UI Biometric is visible or not. Do I have permission to show biometric or not etc. Can…

Pro_And
- 11
- 2
1
vote
0 answers
Android Unit Test Mockito returns null
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…

HyeonSeok
- 589
- 1
- 5
- 18
1
vote
0 answers
How can I provide custom Application class for Unit Test in Android Project
I need a context in some unit test classes. I'm getting errors from 3rd SDKs when I try to provide an application class. So, I want to provide an empty application class for the unit tests.
@RunWith(RobolectricTestRunner::class)
class SampleTest {
…

Cafer Mert Ceyhan
- 1,640
- 1
- 13
- 17
0
votes
0 answers
Use custom test runners for android Unit Test
Is it possible to use a custom test runner for android unit test? (Or junit tests)?
I have tried setting a custom test runner in my default config like
testInstrumentationRunner = "ca.xyz.CustomTestRunner"
But it doesn't work. I checked in the unit…

user1743524
- 655
- 1
- 7
- 14
0
votes
0 answers
Unit tests related to Time fail on bitrise
I have a unit test which passes locally on the machine, but on bitrise it fails. Unit test has time in it.
@Test
fun `If time is later than now in hours, then show in hours`() = runTest {
clock.setInstant(Instant.ofEpochSecond(1686755085)) //Wed…

BRDroid
- 3,920
- 8
- 65
- 143
0
votes
0 answers
mockk, spyk(map) is failing
android project, having some unit test working fine until updated to java 17.
Here is a simplified test to show that the spyk(HashMap()) gets error
@Test
fun test_() {
val metaMapSpy: MutableMap = spyk(HashMap())
…

lannyf
- 9,865
- 12
- 70
- 152
0
votes
2 answers
Kotlin flow test not emitting all value
I am very new in Unit testing , i am trying to test my flow using Turbine library, it is not emitting all value, here is my test
fun `send function should emit Loading and Content states`() = runTest {
// Arrange
val userProfile =…

Jitendra Prajapati
- 1,002
- 1
- 10
- 33
0
votes
0 answers
How to assert a LiveData that change the value two or more times after calling the function under test?
when viewmodel init, if user is already logged in, the livedata _resultEvent.value will change twice
class LoginViewModel @Inject constructor( private val loginUseCase: LoginUser, private val getUserIfLogged: GetUserIfLogged ): ViewModel()…

Tierri Gomes
- 1
- 1
0
votes
0 answers
Unable to start instrumentation testing for app in Android studio
We are trying to implement instrumentation testing for an Android app. While starting testing for app module we getting below exception.
java.lang.NoSuchMethodError: No virtual method getDeclaringClass()Ljava/lang/Class; in class…

sk_dev
- 1
0
votes
0 answers
Unable to test MutableStateflow in android Kotlin
I am trying to test a function in viewmodel that using a flow to emit value, here is the viewmodel code
fun getData(searchResult: AddressSearchResult, lat: String, long: String) =
viewModelScope.launch {
flow {
…

Jitendra Prajapati
- 1,002
- 1
- 10
- 33
0
votes
1 answer
file.exists() returning false in Android unit test
I am trying to test some file related logic in an Android unit test, but whenever I call file.exists() it always returns false for some reason. Here is a boiled down example of a test case I have:
@Test
fun `some test case`() {
val file…

kc_dev
- 578
- 1
- 6
- 21