Wednesday, March 24, 2010

JUnit Setup For Android

Here we are discuss about the JUnit implementation in android application
1. Overview of JUnit in Android
2. Create a Junit Enables Android Application
3. Create a Sample Testcase.

The popular JUnit test framework is integrated into Android.
JUnit, if used properly, brings two major benefits to the test implementation.
    * JUnit enforces the hierarchical organization of the test cases
    * The pattern JUnit is based on guarantees the independence of the test cases and minimizes their interference.

Android test cases classes should inherit from android.test.AndroidTestCase  instead of junit.framework.TestCase.
The main difference between the two is that AndroidTestCase knows about the Context object and provides method to obtain the current Context.
As many Android API methods need the Context object,  this makes coding of Android test cases much easier.            
Make a seperate folder for Junit test Class. Because it should be remove while move to production.

Steps to Implement the JUnit.
1. Create a project
2. Add uses-library and instrumentation in  AndroidManifeast.xml
3. Create a StartupTestSuite
4. Create a Testcase class
5. Run the Apps

Create a Project
Create an android project using your IDE and create a basic component for the application. In this blog i have created a MainActivity which get the text based input from the user.
Requirement  : User enter the His/Her name and password and submit the form.
I have created the following Layout.


  1. This is one of the brilliant post.By read your blog details I came to know about Android JUnit implementation.

    Android app developers

  2. Very priceless blog and actual advisory blog. I absolutely acknowledge your assignment and additionally your idea, anticipation and your content. You guys are done a abundant job.

    Android developers