Questions tagged [android-unit-testing]
61 questions
0
votes
1 answer
Robolectric + JaCoCo | Issue while running unit test and not generating code coverage
I have added Robolectric to get support of Shadow APIs for writing unit tests. Able to get coverage percentage through default Intellij code coverage tool in Android Studio.
Now trying to add JaCoCo to get enhanced coverage report.
I'm using file…

Prat
- 143
- 3
- 17
0
votes
1 answer
android, how to unit test BroadcastReceiver which uses doAsync()
on android app, using Broadcastreceiver to handle the notification click.
public class NotificationReceiver extends BroadcastReceiver {
public void onReceive(final Context context, final Intent intent) {
final PendingResult…

lannyf
- 9,865
- 12
- 70
- 152
0
votes
1 answer
Unit Test Using Junit5 and mockito
I am trying to write a unit test case for android using Junit-5 and mockito But how to write test case for this kind of function when there is a return statment
```public void doSomething() {
if (isTrue()) {
return;
}
…

Hardik Lakum
- 1
- 1
0
votes
1 answer
mockito how to coverage test the inner if block of a static function
Having a static function isNotificationsEnabled which has a if block in the channels for loop to check the notification channel if there is any:
class Utils {
@NonNull
static List…

lannyf
- 9,865
- 12
- 70
- 152
0
votes
1 answer
java.lang.NoClassDefFoundError: androidx/sqlite/db/SupportSQLiteQuery in unit test that worked yesterday
The answer to this question is not "Android unit tests cannot access Android stack modules such as the Room database because on your desktop they are all stubbed out."
I had a bunch of unit tests that tested static methods that happened to be inside…

Phlip
- 5,253
- 5
- 32
- 48
0
votes
1 answer
Unit test two api calls within a method
I have a method that makes an API call and if an error occurs it will retry the call with a different instance of the same service API.
var getResponse = myApi?.getCodeApi()
if (getResponse?.code() ==…

abhishek maharajpet
- 482
- 1
- 4
- 18
0
votes
1 answer
Unit test fails for coroutine if "by inject{parametersOf("someValue")}" is present within coroutine
I have a coroutine in my viewModel which runs perfectly fine. When I try to unit test the same, it throws the following error "Could not create instance for [type:Factory,primary_type:..MyService"
I am injecting a service and making an API call…

abhishek maharajpet
- 482
- 1
- 4
- 18
0
votes
1 answer
Unit Testing : Retrofit 2 Exception - API interfaces must not extend other interfaces
I am not extending any interface and all my interfaces are independent. While performing unit testing I am getting the following exception. During normal API calls, everything works fine.
val retrofit: Retrofit = Retrofit.Builder()
…

abhishek maharajpet
- 482
- 1
- 4
- 18
0
votes
1 answer
Unit testing Room android - This job has not completed yet
I am currently unit testing my local data source which uses Room.
I created a test class:
/**
* Integration test for the [WatchListLocalDataSource].
*/
@RunWith(AndroidJUnit4::class)
@MediumTest
class WatchListLocalDataSourceTest {
private…

Ziv Kesten
- 1,206
- 25
- 41
0
votes
1 answer
How to unit test coruotine with livedata
On the way of learning unit test with mockK I came across with this scenario:
MyViewModel:
private val _spinner: MutableLiveData = MutableLiveData()
val getSpinner : LiveData
get() = _spinner
fun launchCoruotine() {
…

blackHawk
- 6,047
- 13
- 57
- 100
0
votes
1 answer
Following Android docs on unit testing and failing
I am trying to run the simple unit test by following the example here:
https://developer.android.com/training/testing/unit-testing/local-unit-tests
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import…

Cb32019
- 185
- 1
- 13
0
votes
0 answers
Testing Volley with espresso
I built an android app using volley to fetch data from a remote server.
I am trying to test the app using espresso.
can anyone help me with the code for that?
if I take the simplest example, I am trying to get the data from the server, and set it as…

Ariel Applebaum
- 1
- 3
0
votes
0 answers
java.lang.NoClassDefFoundError: Landroidx/room/testing/MigrationTestHelper;
I got following error when i executed my unit test.
java.lang.NoClassDefFoundError: Landroidx/room/testing/MigrationTestHelper;
at java.lang.Class.getDeclaredFields0(Native Method)
at…

Cyrus
- 8,995
- 9
- 31
- 58
0
votes
1 answer
Mockito to mock final field of class
I am trying to mock a final field of class Student
data class Student(
val id: Int,
val name: String,
val marks: Marks
)
data class Marks(
val subject1: String
)
and this is my test class
class StudentTest {
@Test
fun…

Bhavik Kasundra
- 113
- 1
- 9
0
votes
1 answer
Bypass Gradle Unit Tests in Azure Devops?
We have a Azure Pipeline with Gradle Task which runs almost 1700 unit tests. There are some flaky tests (2-3)which is causing the build to fail or partially succeed. Is there a way that I can bypass these flaky tests and have the build run…

abd
- 1