summaryrefslogtreecommitdiffstats
path: root/core/java/android/test
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/test')
-rw-r--r--core/java/android/test/AndroidTestCase.java26
-rw-r--r--core/java/android/test/InstrumentationTestCase.java16
-rw-r--r--core/java/android/test/InstrumentationTestSuite.java2
-rw-r--r--core/java/android/test/TimedTest.java32
4 files changed, 71 insertions, 5 deletions
diff --git a/core/java/android/test/AndroidTestCase.java b/core/java/android/test/AndroidTestCase.java
index de0587a..1015506 100644
--- a/core/java/android/test/AndroidTestCase.java
+++ b/core/java/android/test/AndroidTestCase.java
@@ -30,6 +30,7 @@ import java.lang.reflect.Field;
public class AndroidTestCase extends TestCase {
protected Context mContext;
+ private Context mTestContext;
@Override
protected void setUp() throws Exception {
@@ -43,7 +44,7 @@ public class AndroidTestCase extends TestCase {
public void testAndroidTestCaseSetupProperly() {
assertNotNull("Context is null. setContext should be called before tests are run",
- mContext);
+ mContext);
}
public void setContext(Context context) {
@@ -55,6 +56,25 @@ public class AndroidTestCase extends TestCase {
}
/**
+ * Test context can be used to access resources from the test's own package
+ * as opposed to the resources from the test target package. Access to the
+ * latter is provided by the context set with the {@link #setContext}
+ * method.
+ *
+ * @hide
+ */
+ public void setTestContext(Context context) {
+ mTestContext = context;
+ }
+
+ /**
+ * @hide
+ */
+ public Context getTestContext() {
+ return mTestContext;
+ }
+
+ /**
* Asserts that launching a given activity is protected by a particular permission by
* attempting to start the activity and validating that a {@link SecurityException}
* is thrown that mentions the permission in its error message.
@@ -125,9 +145,9 @@ public class AndroidTestCase extends TestCase {
* to scrub out any class variables. This protects against memory leaks in the case where a
* test case creates a non-static inner class (thus referencing the test case) and gives it to
* someone else to hold onto.
- *
+ *
* @param testCaseClass The class of the derived TestCase implementation.
- *
+ *
* @throws IllegalAccessException
*/
protected void scrubClass(final Class<?> testCaseClass)
diff --git a/core/java/android/test/InstrumentationTestCase.java b/core/java/android/test/InstrumentationTestCase.java
index 2145d7c..22d95d1 100644
--- a/core/java/android/test/InstrumentationTestCase.java
+++ b/core/java/android/test/InstrumentationTestCase.java
@@ -43,11 +43,25 @@ public class InstrumentationTestCase extends TestCase {
*
* @param instrumentation the instrumentation to use with this instance
*/
- public void injectInsrumentation(Instrumentation instrumentation) {
+ public void injectInstrumentation(Instrumentation instrumentation) {
mInstrumentation = instrumentation;
}
/**
+ * Injects instrumentation into this test case. This method is
+ * called by the test runner during test setup.
+ *
+ * @param instrumentation the instrumentation to use with this instance
+ *
+ * @deprecated Incorrect spelling,
+ * use {@link #injectInstrumentation(android.app.Instrumentation) instead.
+ */
+ @Deprecated
+ public void injectInsrumentation(Instrumentation instrumentation) {
+ injectInstrumentation(instrumentation);
+ }
+
+ /**
* Inheritors can access the instrumentation using this.
* @return instrumentation
*/
diff --git a/core/java/android/test/InstrumentationTestSuite.java b/core/java/android/test/InstrumentationTestSuite.java
index 2ab949e..7a78ffb 100644
--- a/core/java/android/test/InstrumentationTestSuite.java
+++ b/core/java/android/test/InstrumentationTestSuite.java
@@ -65,7 +65,7 @@ public class InstrumentationTestSuite extends TestSuite {
public void runTest(Test test, TestResult result) {
if (test instanceof InstrumentationTestCase) {
- ((InstrumentationTestCase) test).injectInsrumentation(mInstrumentation);
+ ((InstrumentationTestCase) test).injectInstrumentation(mInstrumentation);
}
// run the test as usual
diff --git a/core/java/android/test/TimedTest.java b/core/java/android/test/TimedTest.java
new file mode 100644
index 0000000..3a60a25
--- /dev/null
+++ b/core/java/android/test/TimedTest.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.test;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * This annotation can be used on an {@link junit.framework.TestCase}'s test
+ * methods. When the annotation is present, the test method is timed and the
+ * results written through instrumentation output. It can also be used on the
+ * class itself, which is equivalent to tagging all test methods with this
+ * annotation.
+ *
+ * {@hide} Pending approval for public API.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface TimedTest { } \ No newline at end of file