Build 1.0_r1(from source)

android.test
Class ApplicationTestCase<T extends Application>

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by android.test.AndroidTestCase
              extended by android.test.ApplicationTestCase<T>
All Implemented Interfaces:
Test

public abstract class ApplicationTestCase<T extends Application>
extends AndroidTestCase

This test case provides a framework in which you can test Application classes in a controlled environment. It provides basic support for the lifecycle of a Application, and hooks by which you can inject various dependencies and control the environment in which your Application is tested.

Lifecycle Support. Every Application is designed to be accessed within a specific sequence of method calls (see Application for more details). In order to support the lifecycle of a Application, this test case will make the following calls at the following times.

Dependency Injection. Every Application has one inherent dependency, the Context in which it runs. This framework allows you to inject a modified, mock, or isolated replacement for this dependencies, and thus perform a true unit test.

If simply run your tests as-is, your Application will be injected with a fully-functional Context. You can create and inject alternative types of Contexts by calling setContext(). You must do this before calling startApplication(). The test framework provides a number of alternatives for Context, including MockContext, RenamingDelegatingContext, and ContextWrapper.


Field Summary
(package private)  Class<T> mApplicationClass
           
 
Fields inherited from class android.test.AndroidTestCase
mContext
 
Constructor Summary
ApplicationTestCase(Class<T> applicationClass)
           
 
Method Summary
protected  void createApplication()
          Start the Application under test, in the same way as if it was started by the system.
 T getApplication()
           
 Context getSystemContext()
          Return a real (not mocked or instrumented) system Context that can be used when generating Mock or other Context objects for your Application under test.
protected  void setUp()
          This will do the work to instantiate the Application under test.
protected  void tearDown()
          Shuts down the Application under test.
protected  void terminateApplication()
          This will make the necessary calls to terminate the Application under test (it will call onTerminate().
 void testApplicationTestCaseSetUpProperly()
          This test simply confirms that the Application class can be instantiated properly.
 
Methods inherited from class android.test.AndroidTestCase
getContext, scrubClass, setContext, testAndroidTestCaseSetupProperly
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mApplicationClass

Class<T extends Application> mApplicationClass
Constructor Detail

ApplicationTestCase

public ApplicationTestCase(Class<T> applicationClass)
Method Detail

getApplication

public T getApplication()
Returns:
Returns the actual Application under test.

setUp

protected void setUp()
              throws Exception
This will do the work to instantiate the Application under test. After this, your test code must also start and stop the Application.

Overrides:
setUp in class AndroidTestCase
Throws:
Exception

createApplication

protected final void createApplication()
Start the Application under test, in the same way as if it was started by the system. If you use this method to start the Application, it will automatically be stopped by tearDown(). If you wish to inject a specialized Context for your test, by calling setContext(), you must do so before calling this method.


terminateApplication

protected final void terminateApplication()
This will make the necessary calls to terminate the Application under test (it will call onTerminate(). Ordinarily this will be called automatically (by tearDown(), but you can call it directly from your test in order to check for proper shutdown behaviors.


tearDown

protected void tearDown()
                 throws Exception
Shuts down the Application under test. Also makes sure all resources are cleaned up and garbage collected before moving on to the next test. Subclasses that override this method should make sure they call super.tearDown() at the end of the overriding method.

Overrides:
tearDown in class AndroidTestCase
Throws:
Exception

getSystemContext

public Context getSystemContext()
Return a real (not mocked or instrumented) system Context that can be used when generating Mock or other Context objects for your Application under test.

Returns:
Returns a reference to a normal Context.

testApplicationTestCaseSetUpProperly

public final void testApplicationTestCaseSetUpProperly()
                                                throws Exception
This test simply confirms that the Application class can be instantiated properly.

Throws:
Exception

Build 1.0_r1(from source)

Please submit a feedback, bug or feature