android-testing

Android tests BuildConfig field

♀尐吖头ヾ 提交于 2019-12-19 02:38:09
问题 Suppose my build.gradle file defines different values for the same variable that is defined in BuildConfig : android { def INTEGER= "integer" def VARIABLE = "variable" buildTypes { release { buildConfigField BOOLEAN, VARIABLE, "1" } debug { buildConfigField BOOLEAN, VARIABLE, "2" } } } I would like to define BuildConfig value for this variable for androidTest (the one that is created in app/build/generated/source/buildConfig/androidTest/debug/{app_id}/test/BuildConfig.java ) Now, the value is

Using assets in robolectric tests

怎甘沉沦 提交于 2019-12-18 18:58:12
问题 In my robolectric tests I am trying to read a file. Since this file contains just the test data I have put it in assets of the tests. The directory structure looks like this. src/main/assets/prod_data_file src/test/assets/test_data_file However when I try to read the file by getShadowApplication().getAssets().open(MY_FILE_PATH) it gives me FileNotFoundException . Does anybody know how to fix this? 回答1: Since my tests are just reading these files and returning file data as a String I was able

Test Android Activity with different Application class

大憨熊 提交于 2019-12-18 15:28:11
问题 I´m looking for a way to test an Activity with JUnit4 and the ActivityTestRule, but with a different application class (e.g. mocked or inherited). I was able to get this for library projects using the manifest merge and tools:replace="android:name" on the application tag in the androidTest/AndroidManifest.xml. This however does not work for applications. Any ideas how this can be done? 回答1: You can subclass the AndroidJUnitRunner with your own runner and override newApplication() with your

How can I run a single test with gradle android

人走茶凉 提交于 2019-12-18 11:17:45
问题 I'm trying to run the tests with this line... but this launches all tests: ./gradlew -DconnectedAndroidTest.single=LandingActivityTests connectedAndroidTest How can I launch a single test? 回答1: you can run the single android test in two steps: ./gradlew installDebugAndroidTest adb shell am instrument -w -e class com.example.MyInstrumentationTest#testFoo com.example.test/android.support.test.runner.AndroidJUnitRunner https://developer.android.com/tools/testing/testing_otheride.html 回答2: Since

onChildView and hasSiblings with Espresso

大憨熊 提交于 2019-12-18 03:36:11
问题 I am trying to access a button from a specific view. The same view is displayed 6 times. This is the code I am using. public void testTimeConfig(){ onData(withDesc("description")).onChildView(withId(R.id.positive)).perform(click()); } private static Matcher<Object> withDesc(String desc) { return allOf(is(instanceOf(String.class)), is(desc)); } When I run, I get an error: Error performing 'load adapter data' on view 'is assignable from class: class android.widget.AdapterView'. Is this the best

Wait for view pager animations with espresso?

↘锁芯ラ 提交于 2019-12-17 22:54:52
问题 Trying to do some tests with a ViewPager. I want to swipe between tabs, and I don't want to continue until the swipe is complete. But there doesn't appear to be a way to turn off the animation for the view pager (all animations under the developer options are disabled). So this always results in a test failure, because the view pager hasn't completed it's animation, and so the view is not completely displayed yet: // swipe left onView(withId(R.id.viewpager)).check(matches(isDisplayed()))

How do you test an Android application across multiple Activities?

痞子三分冷 提交于 2019-12-17 17:28:18
问题 We are building a complex Android application consisting of many screens and workflows spread across many Activities. Our workflows are similar to what you might see on a Bank's ATM machine, for example, there is an Activity to login in that transitions to a main menu Activity which can transition to other activities based on the user's choices. Since we have so many workflows we need to create automated tests that span multiple activities so we can test a workflow from end to end. For

JUnit test if else case

落爺英雄遲暮 提交于 2019-12-14 03:59:16
问题 How to write test to current method? I use jUnit 4. public void setImage() { if(conditionOne){ myView.setImageOne(); } else { myView.setImageTwo(); } } 回答1: You need to write two tests to cover both the scenarios as below: import org.junit.Test; public class SetImageTest { @Test public void testSetImageForConditionOne() { //write test to make conditionOne true } @Test public void testSetImageForElseCondition() { //write test to make conditionOne false } } 回答2: Okay... there is a flaw in the

Android : How to analyze the trace files programmatically?

核能气质少年 提交于 2019-12-14 03:13:02
问题 I have a list of trace files and I need to analyze them. Is there any way to analyze them programmatically without using the tool traceview ? 回答1: The dmtracedump tool, used with the -o flag, will parse the file and dump it to stdout in a line-oriented human-readable format. You can either parse this output or just clone the file parser from dmtracedump . Sources here. 来源: https://stackoverflow.com/questions/19977128/android-how-to-analyze-the-trace-files-programmatically

Robotium and Jenkins UI testing errors

一个人想着一个人 提交于 2019-12-13 21:07:00
问题 I first ran into this problem when trying to run Robotium UI tests on a MacOS Mini with no monitor. I added Robotium code to test UI clicks on screen, since we want to add some UI automation to our regression testing. The error I get on the Jenkins server is when solo.clickInList(X) is run: junit.framework.AssertionFailedError: AbsListView is not found! [exec] at com.jayway.android.robotium.solo.Waiter.waitForAndGetView(Waiter.java:492) [exec] at com.jayway.android.robotium.solo.Clicker