Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Android Test Framework

Tags:

Android provides various packages for testing like

AndroidTestCase ApplicationTestCase InstrumentationTestCase ActivityInstrumentationTestCase2 ActivityTestCase

I need to know how to decide which package is best suitable for testing my app. Some info is provided in this link

http://developer.android.com/reference/android/test/package-summary.html

But I need more clarity on this...

like image 958
Bharat Pawar Avatar asked Jan 12 '10 06:01

Bharat Pawar


People also ask

What are Android testing frameworks?

Android Testing Framework is powerful tool for developer to write the effective unit test program. The integration of Android and JUnit framework. An addition to Unit Testing is User Interface (UI) tests. These tests relate to UI components of your target application.

How can I test my Android?

Open the app and tap Device diagnosis. Choose Troubleshoot to test the touch-screen display, battery, audio, camera, connectivity, and more. Select Hardware test to run diagnostics on the display, backlight, touch screen, multi-touch capability, flash, front and rear camera, and the proximity sensor.

What is framework in mobile testing?

It is the overall system in which the tests will be automated. It is defined as the set of assumptions, concepts, and practices that constitute a work platform or support for automated testing. A testing framework is responsible for − Defining the format in which to express expectations.

Can I use JUnit 5 in Android?

Instrumentation Test Support There is experimental support for Android instrumentation tests, which requires some additional configuration & dependencies. Furthermore, because JUnit 5 is built on Java 8 from the ground up, its instrumentation tests will only run on devices running Android 8.0 (API 26) or newer.


2 Answers

TestCase – Plain old JUnit test case. It can be extended to test utility classes that are not tied to the Android framework.

AndroidTestCase – It extends JUnit’s TestCase. It’s a lighter testing class compared to ActivityTestCase. It doesn’t need to launch an activity to run it. Its getContext() method allows you to get an injected context if you need one. Since you can get a context from this class, you can inflate your UI objects to test their behaviors.

ActivityInstrumentationTestCase2 – It’s the newer version of ActivityInstrumentationTestCase. ActivityInstrumentationTestCase is deprecated in Android SDK 1.5. It’s a heavier testing class compared to AndroidTestCase. It provides UI and functional testing for a single activity. You can get an injected activity that you are testing on by calling its getActivity() method. The activity being tested is launched and finished before and after each test.

ActivityUnitTestCase – It gives the tested activity an isolated environment. When using it to test an activity, the activity is not attached to the system. This gives you more control over what kind of environment that you want your activity to be tested in.

ApplicationTestCase – It provides testing for Application classes. It can be used to test the life cycle of an application.

InstrumentationTestRunner – The runner that runs the Android test cases.

I just found this..Hope this helps for others...If u want more details like when and how to use, see the APIDemos test application in the samples directory within android SDK.

like image 160
Bharat Pawar Avatar answered Sep 29 '22 12:09

Bharat Pawar


Please see the class hierarchy graph drawn by myself using PowerPoint.

The accepted answer gives enough info in words. I just to make it clear using graph :)

For the InstrumentationTestCase @Zorb asked, it's parent class for ActivityTestCase among others. It enables you to call the getInstrumentation method to get an instance of instrumentation so that you can operate application, activity, and so on.

Class hierarchy graph drawn by myself

like image 42
Better Shao Avatar answered Sep 29 '22 11:09

Better Shao