android-testing

Handler.handleMessage is not called in test, but is called in the app

荒凉一梦 提交于 2019-12-21 05:37:16
问题 I have a service that runs in a separate process. The service spawns a new thread in onCreate() method. This thread sends messages back to the service. If I start the app manually everything works fine - messages are received by the Handler in my service. But in my test handleMessage() method is never get called. How can I fix my test to make handleMessage() method work? Thanks! Service: public class MyService extends Service { private ServiceHandler mHandler; private final int MSG_HELLO

Android SQLite Database Unit Testing

回眸只為那壹抹淺笑 提交于 2019-12-21 03:59:36
问题 I'm new to android app development and I just made a note app. I want to do unit tests for the insertNote, readNote and updateNote methods for the database. How do I go about this? This is the code for my database. Thanks. public class DatabaseManager extends SQLiteOpenHelper { public static final String Database_Name = "Notes Database"; public static final String Table_Name = "notes"; public static final String Column_id = "textId"; public static final String Column_title = "textTitle";

java.lang.SecurityException: Permission Denial: getIntentSender() when using UiAutomation in a test

浪尽此生 提交于 2019-12-21 03:42:15
问题 Whenever I try to use UiAutomation in any test through getInstrumentation().getUiAutomation() , the process crashes with this exception: java.lang.SecurityException: Permission Denial: getIntentSender() from pid=30334, uid=2000, (need uid=1000) is not allowed to send as package android at android.os.Parcel.readException(Parcel.java:1540) at android.os.Parcel.readException(Parcel.java:1493) at android.app.IUiAutomationConnection$Stub$Proxy.disconnect(IUiAutomationConnection.java:225) at

How do I unit test (with JUnit or mockito) recyclerview item clicks

冷暖自知 提交于 2019-12-20 18:10:13
问题 I am currently trying to unit test recyclerview addonitemclick listner, with either junit or mockito. here's my code: private void mypicadapter(TreeMap<Integer, List<Photos>> photosMap) { List<PhotoListItem> mItems = new ArrayList<>(); for (Integer albumId : photosMap.keySet()) { ListHeader header = new ListHeader(); header.setAlbumId(albumId); mItems.add(header); for (Photos photo : photosMap.get(albumId)) { mItems.add(photo); } pAdapter = new PhotoViewerListAdapter(MainActivity.this, mItems

'android.support.test.espresso does not exist' when I want to use it to individual apk test

喜夏-厌秋 提交于 2019-12-20 10:07:09
问题 I need to do some auto testing jobs to an Android application without its source code. I found both robotium and espresso can do this job, I decided to use espresso because its Google support. I would like to sign both the target apk and espresso test apk with the same signature, the target apk is the same as this sample. When I start to coding the espresso test apk, I did the following jobs. The build.gradle in Module:app: apply plugin: 'com.android.application' android { compileSdkVersion

Espresso - Asserting a TextView with async loaded data

一曲冷凌霜 提交于 2019-12-20 09:37:58
问题 I'm writing a UI test with Google Espresso for Android and I'm stuck on how to assert a TextView text, which content is asynchronously loaded from a web service. My current code is: public class MyTest extends BaseTestCase<MyActivity>{ public void setUp() throws Exception { // (1) Tell the activity to load 'element-to-be-loaded' from webservice this.setActivityIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("data://data/element-to-be-loaded"))); getActivity(); super.setUp(); } public void

Getting started with Robotium. EditText not found

坚强是说给别人听的谎言 提交于 2019-12-20 05:30:10
问题 I just getting started with Robotium, writing my first test and I'm getting this weird error: junit.framework.AssertionFailedError: 2131165500 EditTexts are not found! This is my my test case public class TestRegistrationActivity extends ActivityInstrumentationTestCase2<RegistrationActivity>{ private Solo solo; public TestRegistrationActivity() { super(RegistrationActivity.class); } public void setUp() throws Exception { solo = new Solo(getInstrumentation(), getActivity()); } @Override public

Dagger code giving NoClassDefFoundError when Espresso Tests are run, normal run works fine

别说谁变了你拦得住时间么 提交于 2019-12-19 05:16:07
问题 Started exploring Espresso 2.0, but seem to have run into a hiccup. I cannot get the tests to successfully run against any project which includes Dagger. When I run the tests I get the following Exception (entire stacktrace at the end): java.lang.NoClassDefFoundError: com/pdt/daggerexample/model/DaggerExampleAppModule$$ModuleAdapter$ProvideMySingletonProvidesAdapter The application runs when not running from the AndroidInstrumentationTest. Here are some of the relevant files, I've also

Mock server requests Android Espresso UI Testing

这一生的挚爱 提交于 2019-12-19 03:38:04
问题 I am using Espresso to write UI tests for my Android application and would like to mock http requests using MockWebServer. I need to mock authentication responses and sign in the user before the tests are run. Is there a way make the app use mockwebserver so that isntead of making actual requests, I can use respontes enqueued on mockwebserver. So far I have: public class AuthenticationTest { @Rule public ActivityTestRule<Authentication> mActivityTestRule = new ActivityTestRule<>

Android tests BuildConfig field

跟風遠走 提交于 2019-12-19 02:38:15
问题 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