简体   繁体   中英

Using Eclipse to test intents in android

I have recently created an Android application that allows users to add shopping items and lists to a database and need to test its functionality. I have found information on testing whether certain TextViews contain the correct strings etc but that's about it.

I need to have a test project that actually adds food items and tests whether that was successful, I was thinking maybe:

  • Moving to the desired Activity
  • Filling out and submitting the form to add a shopping item
  • Move to the Activity containing all food items and their details
  • Check the item was added correctly

Is this possible to do using an Android test project in Eclipse? If not, are there any other useful tools available for this kind of testing?

You cam use adb shell am to open a activity or send broadcast.
For example. You want to open a activity, the component of it is "com.test/.MainActivity". then you just need to type "adb shell -n com.test/.MainActivity".

I have asked around and a friend of mine told me a list of tools you can use to functionally test android application.

Freeware:

Commercial products:

He recommended FoneMonkey as good enough tool for functional testing. I don't think you can implement functional tests for Android Application using only Android library testing tools without any third party extensions.

Also, see android.testing.ActivityInstrumentationTestCase2<>. You can set up an Intent to be given to the activity under test using setActivityIntent(), then do getActivity() to start the activity under test. There are tutorials in the Developers Guide for learning how to use ActivityInstrumentationTestCase2.

Unfortunately, there doesn't seem to be much documentation for setActivityIntent(), and my guess is that it doesn't test intent filtering.

I think you should do it as unit tests. First ensure that your source Activity is issuing the correct intents by writing a test destination that simply logs all the incoming Intent data. Then write unit tests for the destination, based on setActivityIntent(). You can also use Robotium or MonkeyRunner (part of Android).

If you like to test your database, you can open File Explorer of ADT, save your database to other place and open by other database reader. (such as: SQLite Database Browser )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM