84 questions
1
vote
0
answers
124
views
java.lang.IllegalStateException: Expected `pm dump-profiles` stdout to be either black or saved to '/data/misc/profman/com.app.myapp-primary.prof.txt'
I am using a baseline profile for my app, and it works well when using a benchmark test for measuring performance, but when I try to run the baseline profile generator then it run the specified path ...
0
votes
0
answers
28
views
Listeners for instrumented tests (Android, Gradle)
I want to add a listener for instrumented tests (the src/androidTest subrirectory).
I added this, and I see that the test listeners listen only to unit tests.
(############### is printed always, but ...
0
votes
1
answer
166
views
java.lang.IllegalStateException: Cannot move to state "RESUMED" since the Activity has been destroyed already
I have updated my test cases dependencies from this to this(as given below in code snippet ), since then I am facing this error of java.lang.NullPointerException: Cannot run onActivity since Activity ...
2
votes
2
answers
129
views
Can't use Espresso test parameter injector with org hamcrest Matchers?
Within an existing project with espresso tests, I want to parameterized espresso tests so I add in the project configuration the declaration
implementation 'com.google.testparameterinjector:test-...
1
vote
1
answer
126
views
Execute Junit and Android Test In Sequence
I'm trying to execute two test methods, one of which is a junit and the other is an Android Test in a sequential manner. The first junit test method will be executed, followed by an Android Test. I ...
0
votes
1
answer
2k
views
How to test the ViewModel using Junit, Mockito and Kotlin flows in Android
I tried to test the ViewModel using Junit and Mockito, getting null pointer exception. It returns cannot invoke flow collector. I want to test the responses coming in MpinDataKey, check all parameters ...
0
votes
1
answer
142
views
Android: Mocking GoogleSignIn.getClient is resulting in Null Pointer Exception
Trying to mock static object GoogleSignIn.getClient() method but getting this error from the initialize() method:
getClient(context, gso) must not be null java.lang.NullPointerException: getClient(...
1
vote
0
answers
159
views
Any batter custom solution for retry failed test cases in android espresso
Suggest any solution in kotlin or java for retry 1 or 2 times only failed test case
Tried many solution but does not work any properly
3
votes
1
answer
5k
views
How to write junit test for object class in kotlin/android?
Maybe this is very basic question but could not find anything online.
I have created a object class in kotlin contains few methods. I am calling those from ViewModel and I have written junit test case ...
5
votes
3
answers
1k
views
Configure testLogging for instrumented tests
I would like to configure testLogging for my instrumented tests. However, Gradle seems to ignore my configuration in android.testOptions.unitTests.all.testLogging. There, I have configured that all ...
2
votes
1
answer
3k
views
Android unit testing how to test observable and Subscriber
Hi Following is my part of code which I want to test with various requests but I am unable to test as it is observable subscriber patter any idea how to mock subscriber or how to wait for a result in ...
0
votes
1
answer
3k
views
Android test cases robolectric Shadowlooper idle VS idleFor
using robolectric version 4.5.1
What is the difference between
shadowOf(getMainLooper()).idleFor(1, TimeUnit.MILLISECONDS);
and
shadowOf(getMainLooper()).idle();
shadowOf(getMainLooper()).idle(); ...
-1
votes
1
answer
537
views
Manifest file error while execute first Android instrumented test
Am getting following error while am trying to execute android example instrumented test.
As this is my first instrumented test which am getting error.
Here is my Manifest file and gradle file.
Android ...
5
votes
0
answers
3k
views
Changing from deprecated ActivityTestRule to ActivityScenarioRule breaks test
I recorded an Espresso test using the recorder in Android Studio 4.2.2, which included a single assertion that a text field on my MainActivity UI was showing with the correct text string. I then saved ...
1
vote
1
answer
2k
views
mockito, how to coverage test the catch block
Android app, Having a function calling another function, that function may throw
static string SOME_DEFINE_1 = "some_define_1";
......
void myFunc() {
try {
HashMap<...
3
votes
1
answer
774
views
How to apply a Rule to all test cases in a AndroidJUnitRunner?
I'm trying to apply a TestWatcher as a rule across all my test cases run by a particular runner.
MetadataCollector:
class MetadataCollector : TestWatcher() { ... }
TestRunner:
class TestRunner : ...
1
vote
1
answer
1k
views
Collect JUnit Test Metadata via Annotations
Is there a class/method I could implement within JUnit that is basically a "hook" that runs after each test case finishes, with user-defined (in code) metadata available?
I'm trying to ...
1
vote
1
answer
523
views
How to test ContentProvider with ProviderTestRule in kotlin
I have implemented a ContentProvider that uses a Room database to store the data. The implementation is done in kotlin and it follows the same pattern shown in this Google example.
The ContentProvider ...
6
votes
2
answers
849
views
Espresso test giving: No Koin Context configured. Please use startKoin or koinApplication DSL
I'm running a espresso uiautomator test which runs well when using the green run > button on android studio. (image below)
Yet ./gradlew connectedAndroidTest is giving an error:
No Koin Context ...
0
votes
0
answers
145
views
how to test fragment navigations which is handled by the Activity
I want to test fragment navigations, which is handled by the MainActivity.
for that I have created HomeFragmentTest class
@MediumTest
@RunWith(AndroidJUnit4::class)
class HomeFragmenTest {
@Rule
@...
4
votes
1
answer
1k
views
Get resource from Android test: InstrumentationRegistry.getInstrumentation().getTargetContext() VS myActivityTestRule.getActivity()
I need to get resource from Android test (AndroidJUnit4ClassRunner). What is the recommended way and why?
String some_res_string =
androidx.test.platform.app.InstrumentationRegistry....
7
votes
0
answers
3k
views
Caused by: java.lang.NoSuchMethodError: No static method listOf(Ljava/lang/Object;)Ljava/util/List; in class Lk/v/i; or its super classes
I'm using kotlin collections library (listOf, first, toList, etc,..) methods in our AndroidTest package to run UI tests using AndroidJunit4 runner and I'm coming across these type of errors wherever I ...
2
votes
0
answers
1k
views
Android: Mock a Context for Fragment unit testing
I have a fragment that uses the delegation pattern when a button is clicked.
class FutureMeetingEventViewFragment @Inject constructor(): Fragment() {
@Inject
lateinit var ...
7
votes
2
answers
3k
views
Android FragmentScenario - Unable to find package androidx.fragment.app.testing
I'm getting this error while trying to use FragmentScenario in Android
error: package androidx.fragment.app.testing does not exist
import androidx.fragment.app.testing.FragmentScenario;
...
28
votes
6
answers
120k
views
Mockito lenient() when to use
As I understand, lenient silences the exceptions thrown by StrictStubbing. Based on this, lenient shouldn't be used, maybe only temporary while doing TDD, because strict stubbing exceptions would ...
2
votes
1
answer
894
views
AndroidJUnit4ClassRunner throwing RuntimeException Android
I am developing an Android app. I am writing the Junit test for the android and I am a novice in the Junit test case.
In-app I have one relative layout on click of that I am opening date picker ...
0
votes
1
answer
75
views
How to unit test newly created object inside method?
I have PaymentPresenter with method payWorkOrder(). That method accepts some parameters and based on the logic created two new objects:
WoPayment
PaymentRequest
Here is the code for that:
@RunWith(...
0
votes
1
answer
586
views
How to skip test if a condition is failed Junit (Instrumentation) Testing Android
I am writing test cases for a device testing in which I will have to check some Wifi, Messaging, Camera and Audio Apis but only if the device is capable of that Feature
Example :
@Test
public void ...
1
vote
0
answers
661
views
ClassNotFoundException on IntrumentationRegistry while running Test
I have a utility class in my application that saves the User data from the server onto the SharedPreferences. I was trying to test the utilty class which is named UserLocalStore.kt
I wrote the ...
0
votes
2
answers
682
views
Test text submit on SearchView when using Espresso
How can I submit some text to SearchView in androidTest?
onView(withId(R.id.search_src_text)).perform(typeText("text")) doesn't work for me - app crashes at this line
@Test
fun ...
8
votes
0
answers
2k
views
Gradle connectedCheck fails with 'No tests found' after migrating to AndroidX
I'm working on a multi-module project, and after making the transition from the support libraries to AndroidX, ./gradlew connectedCheck fails:
FAILURE: Build failed with an exception.
* What went ...
1
vote
1
answer
607
views
How do I use an ActivityTestRule with @ClassRule in Kotlin?
I suspect my question is the same as this one, but the code there is incomplete and I must be missing something.
Here's my test class:
@RunWith(AndroidJUnit4::class)
class MyTest {
companion ...
1
vote
0
answers
183
views
Custom runner class AndroidJUnit4 should have a public constructor with signature AndroidJUnit4(Class testClass)"
I am trying to creating a privileged apk and have updated my Android.mk to set the privilege module to true. My apk is compiled on a linux build and not using Android Studio. I also have the following ...
2
votes
0
answers
416
views
Don't fail test if filtering returned no tests in subproject
My connectedDebugAndroidTest fails with
com.android.builder.testing.ConnectedDevice > No tests found.[SM-A310F - 7.0] FAILED
No tests found. This usually means that your test classes are not ...
5
votes
1
answer
528
views
MockitoJUnit tests running in Android Studio but failed when running on the command line
I'm trying to run unit tests using MockitoJUnitRunner; they run fine under Android Studio, but some (not all) tests fail when running in the command line - which is a big deal, I need to be able to ...
28
votes
2
answers
13k
views
Could not find method test() for arguments on Android studio project
In my Android application, I want exclude some test cases in a package so that I used test task in build.gradle file. for example:
apply plugin: 'com.android.library'
test{
exclude '**/calltest/...
1
vote
1
answer
2k
views
Test Orchestrator Sample
Is anyone aware of a sample project that shows how to get test orchestrator working? I checked the google samples and there doesn't seem to be a good sample project that shows test orchestrator.
...
21
votes
2
answers
5k
views
@Config constants parameter could not be found in Robolectric
I am trying to write a Robolectric test. I was following few tutorials where they seem to be using
@RunWith(RobolectricTestRunner::class)
@Config(constants = BuildConfig::class)
to setup the test, ...
3
votes
2
answers
1k
views
"Failed to resolve: org.junit:junit:4.12" with AndroidX Test JUnit
When I try to add dependency on AndroidX Test JUnit 1.0.0-beta01: androidTestImplementation androidx.test.ext:junit:1.0.0-beta01, Gradle Sync fails with the following error:
Failed to resolve: org....
16
votes
1
answer
13k
views
How to run single test class in Android using Gradle command?
In my Android application I have several test classes. If I run following command ./gradlew connectedAndroidTest it runs all the test cases inside the android test folder and generate test report for ...
13
votes
1
answer
4k
views
AndroidJunit4 doesn't accept space function test name?
I have the following test, where the test name is with space and backtick for my instrumental test
@RunWith(AndroidJUnit4::class)
class MyTestClass {
@Rule
@JvmField
var activityRule: ...
0
votes
1
answer
260
views
Context getColor in activity and AndroidJunit4 return different result. Why?
I'm getting color (i.e. R.color.my_white is FFFFFFFF
) from my resource as below
ContextCompat.getColor(getContext(), R.color.my_white)
And when I perform AndroidJUnit4 testing, I also get the same ...
8
votes
1
answer
4k
views
AndroidJUnitRunner unit tests are very slow to execute
I'm using the AndroidJUnitRunner in my project, but the unit tests are painfully slow to execute on a device and emulator both in Android Studio and from the command-line via gradlew.
I'm using the ...
7
votes
0
answers
241
views
Custom Test Orchestrator or callback for start/finish
I'm using the Android Test Orchestrator to run my UI tests and i need to generate a report of the results when all the tests are finished.
I need to have a callback for when the orchestrator starts ...
1
vote
1
answer
6k
views
How to assert that multiple variables have the same value?
I'm writing a jUnit test for a calculation function
double calculate(double val1, double val2);
The function is expected to return the same result if the inputs are "flipped", i.e. it shouldn't ...
3
votes
3
answers
3k
views
How to unit test AsyncTask in android
Consider below code. How can I test this without using third party libraries? The Assert line is never executed, because it is a different thread and the vm stops running. Many thanks!
public class ...
0
votes
1
answer
1k
views
Unit test stops after addOnCompleteListener of the Firebase Task API
I've implemented my first testcase for my App. Before every testcase, I need to login using Firebase.
I've programmed everything in my Firebase class using the Tasks API. The Firebase class is ...
2
votes
1
answer
1k
views
Unable to find instrumentation info for: ComponentInfo{../android.support.test.runner.AndroidJUnitRunner}
I have written a simple Android instrumental test case to test networking operation.
Test case class name: Main3ActivityTest.java
Method name:addNewEmployee
I run my test case using command line then ...
0
votes
0
answers
520
views
Sqlite junit test in android
I have a class called CallWcfTask that extended from extends AsyncTask<Void, Void, Void>. I have declared these fields:
private String _CiName;
private CallWcfCallBack wcfCallBack;
private ...
2
votes
2
answers
3k
views
Gradle, Android, Jacoco and JUnit5
Now with the release of JUnit 5.0 I'm struggling to get code coverage data using jacoco.
My project is multi-module and my problem is that there is no exec file created for each module. Only one in ...