android-testing

Not able to import InstantTaskExecutorRule in my 'jUnit' test case even after adding 'core-testing' dependency - Android testing

纵然是瞬间 提交于 2019-12-24 03:42:53
问题 I am writing test cases for my LoginViewModel . Where I want to perform setValue() operation on my MutableLiveData . To avoid Method getMainLooper in android.os.Looper not mocked Exception I am trying to add the following Rule in my ViewModel file inside test folder . @Rule public InstantTaskExecutorRule mInstantTaskExecutorRule = new InstantTaskExecutorRule(); for that, I have added the following dependency: androidTestImplementation 'android.arch.core:core-testing:1.1.1' as dependency. But

SDK Path not specified

旧城冷巷雨未停 提交于 2019-12-23 20:51:25
问题 Steps I did Downloaded Runner JAR and Client JAR from Square Copied spoon-client-1.1.2.jar to the libs folder, right click --> Add As Library... wrote a simple dummy test: public MainActivityTest() { super(MainActivity.class); } public void test() { Spoon.screenshot(getActivity(), "initial_state"); } Ran MainActivity Ran MainActivityTest (Tests passed) Copied app-debug.apk and app-debug-androidTest-unaligned.apk from the project to the same folder as the spoon-runner-1.1.2-jar-with

Android Testing java.lang.NoClassDefFoundError Error due to Fest-Android

青春壹個敷衍的年華 提交于 2019-12-23 20:47:59
问题 I'm currently implementing Fest for Android into my project but I seem to be running into a dependency issue. If I run my tests without the Fest library included, the tests will run as normal. Once I add in the Fest library then the tests no longer run. An exception is thrown instead. My project uses the following dependencies: compile files('libs/robotium-solo-5.1.jar') androidTestCompile 'com.squareup:fest-android:1.0.8' androidTestCompile 'com.google.code.gson:gson:2.2.4'

How can I deploy and execute an application on a device connected to a remote system?

送分小仙女□ 提交于 2019-12-23 16:16:41
问题 I have a requirement to deploy a test application and issue commands on a device connected to another machine in the same network. I read through http://developer.android.com/tools/help/adb.html#directingcommands but I am not able to find the answer. I tried using adb connect <remote machine IP> but I got unable to connect error. Is there a way to deploy applications and execute adb commands on a device connected to a remote system? 回答1: From the adb tag wiki: Android Debug Bridge (adb) is a

JaCoCo shows 0% coverage, even all tests had passed

ⅰ亾dé卋堺 提交于 2019-12-23 14:20:47
问题 I have written some test cases under androidTest directory. I am using androidx ( testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" ) added dependencies: androidTestImplementation 'androidx.test:runner:1.1.0' androidTestImplementation 'androidx.test:rules:1.1.0' added JaCoCo as dependency, as well. When I run createDebugAndroidTestCoverageReport Gradle task, all the test cases run successfully but coverage is 0% in report I am guessing that is due to this error: V

Is it possible to test an Abstract activity with Robolectric

十年热恋 提交于 2019-12-23 12:43:27
问题 I use abstract activity classes in my code to well, abstract away some features from the activity classes. I'm trying to test the abstract activity classes using Robolectric and the gradle-android-test-plugin using subclasses that extend the abstract class. I can't seem to get it to work though. Does anyone have any experience in this area and is it even possible ? Basic structure is : @RunWith(RobolectricGradleTestRunner.class) public class AbstractActivityTest { private ActivityTest

Mock Build Version with Mockito

为君一笑 提交于 2019-12-23 09:26:44
问题 My target is to mock Build.Version.SDK_INT with Mockito. Already tried: final Build.VERSION buildVersion = Mockito.mock(Build.VERSION.class); doReturn(buildVersion.getClass()).when(buildVersion).getClass(); doReturn(16).when(buildVersion.SDK_INT); Problem is that: when requires method after mock, and .SDK_INT is not a method. 回答1: So far from other questions similar to this one it looks like you have to use reflection. Stub value of Build.VERSION.SDK_INT in Local Unit Test How to mock a

How to test an IntentService with Robolectric?

自古美人都是妖i 提交于 2019-12-23 07:20:35
问题 I'm trying to test the onHandleIntent() method of an IntentService using Robolectric . I'm starting the service with: Activity activity = new Activity(); Intent intent = new Intent(activity, MyService.class); activity.startService(intent); ShadowActivity shadowActivity = Robolectric.shadowOf(activity); Intent startedIntent = shadowActivity.getNextStartedService(); assertNotNull(startedIntent); seems like startedIntent is not null, but onHandleIntent() doesn't seem to be called. how should I

How to test AsyncTask triggered by a click?

徘徊边缘 提交于 2019-12-23 03:44:11
问题 If the AsyncTask is triggered by a click event on a button, how can I test it - how can I wait until the AsyncTask completes? Note I can always execute the AsyncTask directly in my test method, I know how to test such scenario. However, if I insist on on using simulating the onClick event using performClick() can I still test my registration process? MainActivityFunctionalTest public class MainActivityFunctionalTest extends ActivityInstrumentationTestCase2<MainActivity> { // ... public void

Programmatically setting genymotion gps during testing causes “SecurityException: invalid package name” when setting latitude

主宰稳场 提交于 2019-12-23 02:32:18
问题 When testing, I am setting the lat long via Genymotion like so: package com.mypackage.name; public class TestGps extends ActivityInstrumentationTestCase2<MyClass>{ ... //setup just calls super.setup(); public void testLocationButton(){ Gps gps = GenymotionManager.getGenymotionManager(getInstrumentation().getContext()).getGps(); gps.setStatus(Gps.Status.ENABLED); gps.setLatitude(40.7127); // the error happens here gps.setLongitude(74.0059); } } I get the following issue when run: java.lang