Tuesday, January 4, 2011

Android Activities Lifecycle

Android Testing Fundamentals Question

I. Android instrumentation ?
Android instrumentation is a set of control methods to control an Android component independently of its normal life cycle. They also control how Android loads applications.

android instrumentation can load both a test package and the application under test into the same process. Since the application components and their tests are in the same process, the tests can invoke methods in the components, and modify and examine fields in the components.

Normally, an Android component runs in a lifecycle determined by the system. For example, an Activity object's lifecycle starts when the Activity is activated by an Intent. The object's onCreate() method is called, followed by onResume(). When the user starts another application, the onPause() method is called. If the Activity code calls the finish() method, the onDestroy() method is called. The Android framework API does not provide a way for your code to invoke these callback methods directly, but you can do so using instrumentation.
Also, the system runs all the components of an application into the same process. You can allow some components, such as content providers, to run in a separate process, but you can't force an application to run in the same process as another application that is already running.
With Android instrumentation, though, you can invoke callback methods in your test code. This allows you to run through the lifecycle of a component step by step, as if you were debugging the component. The following test code snippet demonstrates how to use this to test that an Activity saves and restores its state:
    // Start the main activity of the application under test
    mActivity = getActivity();

    // Get a handle to the Activity object's main UI widget, a Spinner
    mSpinner = (Spinner)mActivity.findViewById(com.android.example.spinner.R.id.Spinner01);

    // Set the Spinner to a known position
    mActivity.setSpinnerPosition(TEST_STATE_DESTROY_POSITION);

    // Stop the activity - The onDestroy() method should save the state of the Spinner
    mActivity.finish();

    // Re-start the Activity - the onResume() method should restore the state of the Spinner
    mActivity = getActivity();

    // Get the Spinner's current position
    int currentPosition = mActivity.getSpinnerPosition();

    // Assert that the current position is the same as the starting position
    assertEquals(TEST_STATE_DESTROY_POSITION, currentPosition);
 
II. Test Case Classes
 
 1.AndroidTestCase:
   It extend both TestCase and Assert. It provides the
   JUnit-standard setUp() and tearDown() methods, as well as well as
   all of JUnit's Assert methods. In addition, it provides methods for testing permissions, and a
   method that guards against memory leaks by clearing out certain class references. 
This test case provides a framework in which you can test Application classes in
   a controlled environment.
 
Class Overview: Extend this if you need to access Resources or other things that depend on Activity Context.
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/test/AndroidTestCase.java 
 2.ApplicationTestCase
The test case can be useful in verifying that the <application> element in the manifest file is correctly
    set up. Note, however, that this test case does not allow you to control testing of the
    components within your application package.
3.InstrumentationTestCase
for testing some part of the activity in isolation
 
4.MockObjectClass
       Mock Context class implements all methods in a non-functional way and throw    UnsopportedOperationException.
   This can be used to inject other dependencies, mocks, or monitors into the classes under testing. A fine control can be obtained extending this class.
   Extend this class to provide your desired behaviour overriding the correspondent methods.
   This document can be read in Google Docs : https://docs.google.com/View?id=ddwc44gs_21737cgtvfj

full details can be read at: http://developer.android.com/guide/topics/testing/testing_android.html
 

 
 
 

Tuesday, September 28, 2010

Expect Excellent !

To begin, let have a question:
what do you expect excellent on ?

we expect excellent from ourselves, expect excellent from every pieces of our service, expect excellent from our each products, expect excellent to satisfy any fastidious user :-)

we expect excellent, completely perfect on every each resource/person. Yes, that way will help to notice the resources that they might keep forward for working, learning and definitely fighting against negligence on every pieces of battle.

Wednesday, September 22, 2010

Make contact !

Technology has been drastically changed behavior of any person in the world, why ? it brings to the convenience, intelligence,quickness,simplicity... and some how continue to improve ever to satisfy any need.

So, i am still interesting in the way that people contact to each other in the old day. how many way, people can contact to each other in the old day?
Sending a bird with a message and waiting for feedback :), i really don't understand how can the bird find to the destination and get back to their home :) :) :)  do not know the old Vietnamese has used this way ? (perhaps it only happens in the Chinese film however it is recorded like a popular way)
If you live near an ocean just throw your message into the ocean and eventually the receiver will get it :) :} :}, how can you imagine, right ? don't look me like a fool ? the old and famous Vietnamese has been used it, a princess An Tiem has been thrown several watermelons (his message) into the ocean and eventually the king got it.
more and more people presents in the world and we changed that way, now what? we have mail-man riding on a beautiful-horse/handsome-horse  (tuấn mã :) ), and then mail-man riding on bicycle (phoenix or Martin 07) then a motorbike (SH or Dylan or @ sometimes) and then bunch of mails in a car that is called transfer-mail-car.
it still takes a long time to transfer a mail, from another area in one country and from other country to each other. people begins to go so far from their home, right? or people need to know or discover or get to clear what happens or what it look like in other area/region...

and now when a world likes a village (make a video-phone-call or e-mail or instant message... to any place (domestic or international) or any person who has relationship or out of blue ...is very simple), people continue to discover what happen out side of the world, it's there a place where human can live out side of the earth ? or try to contact to alien ? maybe,who knows, once-day we will move to another place out of the earth ? future will have the answer?

Grey sky and big rain in the evening,