Library Technology – Reviews, Tips, Giveaways, Freeware

Android Test Framework: Test Your Android Application Activity

Posted In Android, Smartphone reviews, Technology devices - By Techtiplib on Saturday, December 7th, 2013 With No Comments »

After completing the development of Android applications, it is inevitable to perform its testing, so that it can be faultlessly uploaded on the play store. There are two categories of android app testing, which are tests requiring an android system and tests requiring JVM. JUnit is a test framework, which can be utilized to run direct testing of Java classes and these will not be invoked by the Android API. Android, in any case, offers separate Junit extensions to test Android API.

android-apps

The JUnit test cannot be used on JVM due to distinct options in the Android program JAR file “ android.jar”, which is just a placeholder. Calling them may result in the generation of RUNtime Errors. All this happens because of the absence of Android framework code in the android.jar file. The JAR file is only used for the Java compiler for the deployment of the app on any Android device. When the application is loaded on an Android device, then the android.jar file is utilized on that particular device.

In case there are no extra libraries, then it might get incomprehensible for you to do the testing of android system classes on the JVM specifically. In order to perform the android class testing, it is essential to run them on the Android device or make usage of an emulator that expends a great deal of time. There are two types of tests – unit tests and functional tests. The purpose of unit tests is to test the functionality of a specific component only, whereas functional testing is done to check if the activity has correctly started or not.

Test Hooks Of Android Framework

Android Framework

Instrumentation

Hooks are applied by the android testing API into the component life-cycle of android.

These hooks are known as an instrumentation API that permits the tests to control and manage the android application life-cycle.

Instrumentation API permits you to run both the android project and the test project simultaneously and hence, assist the test project to invoke methods directly from the basic android project.

PRE_andevcon_instrumentation-101

Distinct Test Classes And Annotations In Android

Android Assertion And Mock Classes

Not only the testing API android provides the MoreAsserts and ViewAsserts classes, but also the basic JUnit Assert class. With the help of the mock classes, you can run stand-alone tests from a running system by overriding the normal operations.

Android Test Classes

The test framework of android depends upon JUnit3, because of which the test needs to expand TestCase class along with this all the test methodologies should start with a test. With the help of the android test case, the components of android apps can be tested. Few of the test classes are stated below:

  • ApplicationTestCase: It offers methods to test the functionality and process of the application objects.
  • AndroidTestCase: It provides different methods to permissions.
  • InstrumentationTestCase: Base class in terms of using instrumentation methods.

Android Activity Testing

If you want to run a stand-alone activity testing, then you can make use of ActivityUnitTestCase. With the help of this, you can inspect the framework of an activity, so that you can check whether the action is getting triggered accordingly. In case you want to access an instant, you can use the method getStartedActivityIntent() to access an intent.

  • ActivityUnitTestCase: Used to check the layouts
  • ActivityInstrumentationTestCase2: It is a functional testing 
  • getInstrumentation(): Allow you to send click events

Android Service Testing

Use the ServiceTestCase class to run a service testing. Communicate with the service with startService() as well as bindService() methods. On calling the startService() first time, onCreate() function of the specific service is triggered; however, on repeating startService() command, onStartCommand() method is called.

Author bio:

David Meyer has been working with CSSChopper since years and is a proficient and skilled web developer. He is an amazing blogger, who always share his knowledge through his state-of-the-art blogs. Choose CSSChopper for your projects and get android app development services from expert programmers at affordable rates.

More contents in: ,

About -

Hey, this blog belongs to me! I am the founder of TechTipLib and managing editor right now. And I love to hear what do you think about this article, leave comment below! Thank you so much…