ApplicationTestCase
abstract class ApplicationTestCase<T : Application!> : 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 android.app.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.
- The test case will not call onCreate() until your test calls
createApplication(). This gives you a chance to set up or adjust any additional framework or test logic before onCreate().
- After your test completes, the test case
tearDown method is automatically called, and it will stop & destroy your application by calling its onDestroy() method.
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 AndroidTestCase#setContext(Context). You must do this before calling createApplication(). The test framework provides a number of alternatives for Context, including MockContext, RenamingDelegatingContext, and ContextWrapper.
Summary
| Public methods |
| open T |
|
| open Context! |
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.
|
| Unit |
This test simply confirms that the Application class can be instantiated properly.
|
| Protected methods |
| Unit |
Start the Application under test, in the same way as if it was started by the system.
|
| open Unit |
This will do the work to instantiate the Application under test.
|
| open Unit |
Shuts down the Application under test.
|
| Unit |
This will make the necessary calls to terminate the Application under test (it will call onTerminate().
|
| Inherited functions |
|
|
From class Assert
Unit |
assertEquals(message: String!, expected: Any!, actual: Any!)
Asserts that two objects are equal. If they are not an AssertionFailedError is thrown with the given message.
|
Unit |
assertEquals(expected: Any!, actual: Any!)
Asserts that two objects are equal. If they are not an AssertionFailedError is thrown.
|
Unit |
assertEquals(message: String!, expected: String!, actual: String!)
Asserts that two Strings are equal.
|
Unit |
assertEquals(expected: String!, actual: String!)
Asserts that two Strings are equal.
|
Unit |
assertEquals(message: String!, expected: Double, actual: Double, delta: Double)
Asserts that two doubles are equal concerning a delta. If they are not an AssertionFailedError is thrown with the given message. If the expected value is infinity then the delta value is ignored.
|
Unit |
assertEquals(expected: Double, actual: Double, delta: Double)
Asserts that two doubles are equal concerning a delta. If the expected value is infinity then the delta value is ignored.
|
Unit |
assertEquals(message: String!, expected: Float, actual: Float, delta: Float)
Asserts that two floats are equal concerning a positive delta. If they are not an AssertionFailedError is thrown with the given message. If the expected value is infinity then the delta value is ignored.
|
Unit |
assertEquals(expected: Float, actual: Float, delta: Float)
Asserts that two floats are equal concerning a delta. If the expected value is infinity then the delta value is ignored.
|
Unit |
assertEquals(message: String!, expected: Long, actual: Long)
Asserts that two longs are equal. If they are not an AssertionFailedError is thrown with the given message.
|
Unit |
assertEquals(expected: Long, actual: Long)
Asserts that two longs are equal.
|
Unit |
assertEquals(message: String!, expected: Boolean, actual: Boolean)
Asserts that two booleans are equal. If they are not an AssertionFailedError is thrown with the given message.
|
Unit |
assertEquals(expected: Boolean, actual: Boolean)
Asserts that two booleans are equal.
|
Unit |
assertEquals(message: String!, expected: Byte, actual: Byte)
Asserts that two bytes are equal. If they are not an AssertionFailedError is thrown with the given message.
|
Unit |
assertEquals(expected: Byte, actual: Byte)
Asserts that two bytes are equal.
|
Unit |
assertEquals(message: String!, expected: Char, actual: Char)
Asserts that two chars are equal. If they are not an AssertionFailedError is thrown with the given message.
|
Unit |
assertEquals(expected: Char, actual: Char)
Asserts that two chars are equal.
|
Unit |
assertEquals(message: String!, expected: Short, actual: Short)
Asserts that two shorts are equal. If they are not an AssertionFailedError is thrown with the given message.
|
Unit |
assertEquals(expected: Short, actual: Short)
Asserts that two shorts are equal.
|
Unit |
assertEquals(message: String!, expected: Int, actual: Int)
Asserts that two ints are equal. If they are not an AssertionFailedError is thrown with the given message.
|
Unit |
assertEquals(expected: Int, actual: Int)
Asserts that two ints are equal.
|
Unit |
assertFalse(message: String!, condition: Boolean)
Asserts that a condition is false. If it isn't it throws an AssertionFailedError with the given message.
|
Unit |
assertFalse(condition: Boolean)
Asserts that a condition is false. If it isn't it throws an AssertionFailedError.
|
Unit |
assertNotNull(object: Any!)
Asserts that an object isn't null.
|
Unit |
assertNotNull(message: String!, object: Any!)
Asserts that an object isn't null. If it is an AssertionFailedError is thrown with the given message.
|
Unit |
assertNotSame(message: String!, expected: Any!, actual: Any!)
Asserts that two objects do not refer to the same object. If they do refer to the same object an AssertionFailedError is thrown with the given message.
|
Unit |
assertNotSame(expected: Any!, actual: Any!)
Asserts that two objects do not refer to the same object. If they do refer to the same object an AssertionFailedError is thrown.
|
Unit |
assertNull(object: Any!)
Asserts that an object is null. If it isn't an AssertionError is thrown. Message contains: Expected: but was: object
|
Unit |
assertNull(message: String!, object: Any!)
Asserts that an object is null. If it is not an AssertionFailedError is thrown with the given message.
|
Unit |
assertSame(message: String!, expected: Any!, actual: Any!)
Asserts that two objects refer to the same object. If they are not an AssertionFailedError is thrown with the given message.
|
Unit |
assertSame(expected: Any!, actual: Any!)
Asserts that two objects refer to the same object. If they are not the same an AssertionFailedError is thrown.
|
Unit |
assertTrue(message: String!, condition: Boolean)
Asserts that a condition is true. If it isn't it throws an AssertionFailedError with the given message.
|
Unit |
assertTrue(condition: Boolean)
Asserts that a condition is true. If it isn't it throws an AssertionFailedError.
|
Unit |
fail(message: String!)
Fails a test with the given message.
|
Unit |
fail()
Fails a test with no message.
|
Unit |
failNotEquals(message: String!, expected: Any!, actual: Any!)
|
Unit |
failNotSame(message: String!, expected: Any!, actual: Any!)
|
Unit |
failSame(message: String!)
|
String! |
format(message: String!, expected: Any!, actual: Any!)
|
|
|
|
Public constructors
<init>
ApplicationTestCase(applicationClass: Class<T>!)
Public methods
getApplication
open fun getApplication(): T
Deprecated.
| Return |
T |
Returns the actual Application under test. |
getSystemContext
open fun getSystemContext(): Context!
Deprecated.
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.
| Return |
Context! |
Returns a reference to a normal Context. |
testApplicationTestCaseSetUpProperly
fun testApplicationTestCaseSetUpProperly(): Unit
Deprecated.
This test simply confirms that the Application class can be instantiated properly.
| Exceptions |
java.lang.Exception |
|
Protected methods
createApplication
protected fun createApplication(): Unit
Deprecated.
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 AndroidTestCase#setContext(Context), you must do so before calling this method.
setUp
protected open fun setUp(): Unit
Deprecated.
This will do the work to instantiate the Application under test. After this, your test code must also start and stop the Application.
tearDown
protected open fun tearDown(): Unit
Deprecated.
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.
| Exceptions |
java.lang.Exception |
|
terminateApplication
protected fun terminateApplication(): Unit
Deprecated.
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.