android-testing

How to inject a dependency when testing an Android activity without a third-party framework?

主宰稳场 提交于 2020-01-24 02:58:45
问题 I want to test an Android activity CommentActivity that normally constructs and uses an instance of CommentsDataSource (both are classes that I wrote). public class CommentActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { : CommentsDataSource = new CommentsDataSource(..); : } : } I'm willing to create MockCommentsDataSource myself and would like to avoid using a third-party mocking framework. (Why? Because I'm a teaching trying to reduce the amount of

No tests found when running instrumented tests with AndroidX

陌路散爱 提交于 2020-01-21 11:49:07
问题 I'm trying to run the standard ExampleInstrumentedTest in my Android project (which uses AndroidX), but get "No tests found" error instead. I've looked through the other questions and the documentation and I'm pretty sure I've done everything right, but maybe I'm overlooking anything? Here is my app's build.gradle: apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' android { compileSdkVersion 28 defaultConfig { minSdkVersion 24 targetSdkVersion

Verify a static method was called by another static method in PowerMock

依然范特西╮ 提交于 2020-01-14 05:28:11
问题 I have a Tool class with two static methods, doSomething(Object) and callDoSomething(). The names are intuitive in that callDoSomething delegates its call to doSomething(Object); public class Tool { public static void doSomething( Object o ) { } public static void callDoSomething() { doSomething( new Object()); } } I have a Test class for Tool and I'd like to verify if doSomething(Object) was called (I want to do Argument Matching too in the future) @RunWith( PowerMockRunner.class )

Android http testing with Robolectric

安稳与你 提交于 2020-01-12 04:50:07
问题 I have an Android app where the main part of the app is the APIcalls.java class where I make http requests to get data from server an display the data in the app. I wanted to create unit test for this Java class since it's the most part of the app. Here is the method for getting the data from server: StringBuilder sb = new StringBuilder(); try { httpclient = new DefaultHttpClient(); Httpget httpget = new HttpGet(url); HttpEntity entity = null; try { HttpResponse response = httpclient.execute

How do I detect a view that I have created programmatically in espresso

别说谁变了你拦得住时间么 提交于 2020-01-07 03:54:07
问题 I have this line of Espresso test code: onView(withId(R.id.rvWorkDaySchedule)).perform(swipeDown()); And rvWorkDaySchedule is shown in red in the editor of Android Studio because there is no such XML view id in the layouts - I create this RecyclerView programmatically. So how do I detect views that have been inflated programmatically with Espresso? 回答1: First of all, Espresso allows you to use Hamcrest matchers in tests. Hamcrest 1.3 Quick Reference. The most useful for catching the

Espresso - Radio button, how to choose data

霸气de小男生 提交于 2020-01-06 06:19:11
问题 I'm using espresso for testing my android app. I have a radio group in my layout file <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <RadioGroup android:id="@+id/radio_number_group" android:layout_width="match_parent" android:layout_height="wrap_content" /> </ScrollView> And radio button is added programmatically. The data is fetched from an API and added!! if (mvns.size() > 0) { radioGroup.removeAllViews(); for (String s : mvns) { RadioButton rb = new

Correct way to take screenshot with Robotium and Cucumber

若如初见. 提交于 2020-01-05 03:07:24
问题 Which is the best way to take a screenshot when one scenario fails using Robotium and Cucumber ? I have tried (without success, because it doesn't execute runTest method) with this: import cucumber.api.CucumberOptions; import cucumber.api.java.After; import cucumber.api.java.Before; @CucumberOptions(features = "features", tags = {"~@ignore"}) public class CustomInstrumentationTestCase extends ActivityInstrumentationTestCase2<LaunchActivity> { protected Solo solo; public

Android Test stopping in instantiating tests

六月ゝ 毕业季﹏ 提交于 2020-01-05 02:57:07
问题 When i run my ui test, it just stopping in instantiating tests... Uploading file: local path: /Users/eclo/AndroidStudioProjects/Minicooper4android/Minicooper4android/app/build/outputs/apk/NAMmogujie714-uiTest-debug-androidTest-unaligned.apk remote path: /data/local/tmp/com.mogujie.test No apk changes detected. Skipping file upload, force stopping package instead. DEVICE SHELL COMMAND: am force-stop com.mogujie.test Running tests What's wrong? 来源: https://stackoverflow.com/questions/31468259

Why doesn't PackageManager locate Activity from Instrumentation Registry (UI-automator)?

倖福魔咒の 提交于 2020-01-03 17:02:41
问题 Why doesn't PackageManager from Instrumentation Registry (UI-automator) locate the Activity? Intent { pkg=com.me.Activity1 } My application has 3 entry points. Three Activities, each represented by an icon. I am trying to run a ui-automator test to press an icon and launch the corresponding activity. In Android Studio 2.2, when I select app and press Run, then it runs correctly and launches the Activity. However, in ui-automator it fails both on the Nexus 5 device and in the emulator. However

How not to run a particular test when executing connectedAndroidTest?

风流意气都作罢 提交于 2020-01-03 15:34:30
问题 It takes long to execute some of our instrumented tests. So I'd like not to run them when I run all the other instrumented tests with gradle connectedAndroidTest . Why don't I annotate those tests with @Ignore? Because I'd like to run them later using adb shell as described here. Like this: Running all tests except those in a particular class: adb shell am instrument -w -e notClass com.android.foo.FooTest com.android.foo/android.support.test.runner.AndroidJUnitRunner If I marked those tests