FAQ Database Discussion Community
android,android-studio,android-testing,android-espresso
I'm setting up Android app structure with Gradle and Android Studio and Espresso UI testing for a project. No matter what I try, the androidTest folder never appears in AndroidStudio's project structure. Project (root) build.gradle: buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.2.2' } } allprojects { repositories...
java,android,robotium,android-testing
How is it possible to restart an activity that was ended using Robotium's solo.goBack()? The following does not restart the activity: (the test finishes ok) solo.goBack(); try { // recreate activity here runTestOnUiThread(new Runnable() { public void run() { getInstrumentation().callActivityOnCreate(getActivity(), null); getInstrumentation().callActivityOnStart(getActivity()); getInstrumentation().callActivityOnResume(getActivity()); }}); } How do you restart an...
android,android-testing,servicetestcase
According to the official Service Testing documentation it is important to ensure that the onCreate() is called in response to Context.startService() and the onDestroy() is called in response to Context.stopService(). How can I implement such a test by extending the ServiceTestCaseclass?
android,android-testing
In a linear layout with 2 views A and B, how do I assert that view B is to the right of view A?
android,android-testing,spoon
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...
android,robolectric,android-testing,circleci
I'm running into an issue where my robolectric tests pass in my terminal with: ./gradlew test and the same command, properly configured with all the tools on circleci gives me this error: java.lang.RuntimeException: java.lang.IllegalArgumentException: maxSize <= 0 at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:238) at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:185) at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54) at...
selenium,android-testing,selendroid
I want to handle server timeout in programmatically. My codes goes like this. SelendroidConfiguration config = new SelendroidConfiguration(); config.addSupportedApp("apk/test.apk"); selendroidServer = new SelendroidLauncher(config); URL url = new URL("http://localhost:4444/wd/hub"); // ------------------------------------------------------- SelendroidCapabilities test= SelendroidCapabilities .device("com.test.android:1.0"); driver = new SelendroidDriver(url, test); ...
android,android-testing,android-espresso
The scenario is when the user click on the "Download" button, the data (a music/an image etc.) starts being downloaded from the internet. When the download is finished, the button changes it label text to "Open". The user then click on that "Open" button. What I've done sofar is: onView(allOf(withId(R.id.button),withText("Download"))).check(matches(isClickable())).perform(click());...
android,android-testing
So I'm getting a NoSuchMethodError when running my Activity/instrumentation tests from Android Studio, on the code line which tries to call a method in a library module from the unit test. So this is my test: public class MainActivityTest extends ActivityInstrumentationTestCase2 { public void testMainActivity() { final MainActivity target =...
android,testing,robotium,android-testing
I'm struggling to catch expected exceptions in test cases of my Android app using the class ActivityInstrumentationTestCase2. I wrote a very simple scenario that is raising the issue, and once this is solved I can probably do the same thing for my app. The snippet of the simple scenario is...
java,android,android-testing,android-espresso,android-instrumentation
I am stuck and will be glad to get any help! I am writing tests for an android library. The task is to make some actions in an activity and check that library responds correctly. My problem is that my test finishes just after all actions in activity are done...
android,google-play,android-testing
I want to publish my alpha APK on google's developer console. The question is whether it will be visible in the google play store? Or will it be only available for testers to whom I send the opt-in link?
java,android,junit,junit4,android-testing
I've managed to get my Android project transitioned over to JUnit4, and of course the main reason I wanted to do it isn't working. Would love any help if anyone's got ideas here. The problem I'm trying to solve is that I want to automatically skip certain tests if the...
java,android,logcat,assert,android-testing
I'm curious I've never seen in my LogCat any messages marked as Assert. I have read documentation as here and here, but actually I didn't get the purpose of it and how it can be useful? I got that it throws errors, but why it is different with for example...
java,android,junit,junit4,android-testing
This is my test code: @RunWith(AndroidJUnit4.class) @SmallTest public class WelcomeActivityTests extends BaseTest { ApplicationController applicationController; @Rule public ActivityTestRule<WelcomeActivity> activityTestRule = new ActivityTestRule<>(WelcomeActivity.class); ArgumentCaptor<Callback> argumentCaptor; @Before @Override public void setUp() { applicationController = (ApplicationController) InstrumentationRegistry.getTargetContext().getApplicationContext(); applicationController.setMockMode(true);...
android,android-bluetooth,android-testing,android-espresso
In my application I'm turning on BlueTooth when first Activity starts up. It results in the system dialog asking for the authorization to activate the BlueTooth. How can I asset that this dialog is present and click on the "Yes" Button with Espresso ? Is it possible ? I tried...
android,unit-testing,android-testing
I know it is a tedious topic for all android developers. But what exactly is the correct approach to Android Testing? This is what I can picture. 70% Unit testing (JUnit to test all business logic, network layer, database layer etc...) 20% Integration test (Perhaps testing against mock server? mainly...
android,junit,dalvik,android-testing
I'm planning to port my JUnit tests to Android Testing framework. Some of the tests only involve the JVM but not the Android system, is it still necessary to port them? Android is using Dalvik and will replace it with ART(Android Runtime) in Lollipop, both of which are different from...
android,junit4,android-testing
Is this an issue or did I forget to implement something particular? When I don't run it with JUnit 4 it works fine....
android,android-activity,android-view,android-testing
A common situation I face is that I wish to test a custom View visibly on screen while it is being developed as part of a large application. I realise that unit testing exists, particularly using ActivityUnitTestCase, but as far as I understand these frameworks don't actually attach the components...
android,junit4,android-testing,android-espresso
In my test case I have to record for 1 hour, in robotium solo.sleep(600000) had done my work, but In espresso I am confused with IdlingResource concept. I have to start recording and wait for some time(depending on the type of test) 15mins, 60mins etc. Equivalent code in robotium solo.clickOnView(solo.getView("start_record"));...
android-testing
I'm using the new Android Testing Support Library (com.android.support.test:runner:0.2) to run Instrumentation Tests (a.k.a Device or Emulator Tests). I annotate my test class with @RunWith(AndroidJUnit4.class) and use Android Studio to run them. For my test cases I need a Context instance. I can get it with InstrumentationRegistry but it has...
android,junit4,android-testing,android-espresso,ui-testing
I have a custom layout for listview, I want to click on a imageview placed in the list view item, overflow icon of the first item in the list view. I want to click on last imageview with id "rcOverflow" My layout, <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="left" android:paddingBottom="10dp" android:paddingTop="5dp"> <ImageView...
android,android-studio,gradle,jvm,android-testing
We are trying to introduce the new Android Unit Testing Support to our project. For library project, it fails to find the src/main/java classes when running with gradlew. Running the test from Android Studio works as expected. Running the test with gradle in an app project works as expected. Running...
java,android,junit,android-testing
I wanted to add two different test files in my project. One for instrumental tests and the other one for junit tests. I have added src/androidTest/java file into my project. Everything worked perfectly, java file changed its color to green, but when I added src/test/java it didn't work. The file...
android,unit-testing,android-testing
I am using Android Studio 1.2 Say I have a simple method add in some class MyAdder public int add(int a,int b) { return a+b; } I want to perform unit test and use assertions to perform the test for the above mentioned code. I found it tough to begin...
android,junit4,robotium,android-testing,android-espresso
I am switching from robotium to espresso, I am writing tests using apk, I dont have access to code. In robotium using solo.getView("view-id") we can access the view but I am not geting how to do it in espresso? espresso witId() method needs R.id.viewid which I dont have access. public...
android,unit-testing,android-studio,android-testing
I am working through an android app tutorial course on udacity.com. I have come to a lesson where it's introducing testing. However, the video for the current class is showing how to run a test where only one run test option is available. seen here: https://youtu.be/CHb8JGHU290?t=170 but my android studio...
android,android-testing,android-espresso
We have three BuildVariants: release, debug and develop. The first are the defaults from AndroidStudio. The last is for our internal testing. Here are the configs: (There is nothing different than Signing Config) We have imports the following in our build.gradle: dependencies { // App dependencies compile 'com.android.support:support-annotations:22.0.0' compile 'com.google.guava:guava:18.0'...
android,unit-testing,android-testing
In my common library code I am trying to create a inflater helper to manage multiple views in a ListView. This code is intended to be used in many projects. I would like to write unit test for the following code for that I need some xml layout to be...
android,android-testing
I'm trying to test some code that makes the call context.getResources().openRawResource(rawResourceId) (docs), where the resource is a text file to be read from. My test class extends AndroidTestCase. How would I be able to mock this call to return whatever file contents I want?...
android,android-testing
Can someone explain the main differences between these types of Android gradle tasks? check - Runs all checks. connectedAndroidTest - Installs and runs the tests for Build 'debug' on connected devices. connectedCheck - Runs all device checks on currently connected devices. deviceCheck - Runs all device checks using Device Providers...
android,mockito,android-testing,greendao
I am new to android testing and trying to write unit tests (running on local jvm) using mockito in Android Studio. My IDE setup (gradle scripts) is done so far. dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') // Unit testing dependencies. testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.19' } In my app I...
android,android-studio,android-source,android-testing
How to attach sources from android.support.test.* for debugging in AS? Tried downloading sources from https://android.googlesource.com/platform/frameworks/testing but the version doesn't seem to match my testing library version. Testing sources (for instance AndroidJunitRunner) don't seem to be available via sdk manager, am I missing something ?...
android,junit4,robotium,android-testing,android-espresso
I am a robotium user now switching to Espresso can anyone tell me how to write tests using apk in espresso, as we do in robotium without having acccess to the code but using app apk. And how to access views without R.id.viewid in espresso? as we do in robotium...