Loading core/java/android/test/AndroidTestCase.java +23 −3 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -54,6 +55,25 @@ public class AndroidTestCase extends TestCase { return mContext; } /** * 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} Loading test-runner/android/test/AndroidTestRunner.java +4 −2 Original line number Diff line number Diff line Loading @@ -158,16 +158,18 @@ public class AndroidTestRunner extends BaseTestRunner { mTestResult.addListener(testListener); } Context testContext = mInstrumentation.getContext(); for (TestCase testCase : mTestCases) { setContextIfAndroidTestCase(testCase, mContext); setContextIfAndroidTestCase(testCase, mContext, testContext); setInstrumentationIfInstrumentationTestCase(testCase, mInstrumentation); testCase.run(mTestResult); } } private void setContextIfAndroidTestCase(Test test, Context context) { private void setContextIfAndroidTestCase(Test test, Context context, Context testContext) { if (AndroidTestCase.class.isAssignableFrom(test.getClass())) { ((AndroidTestCase) test).setContext(context); ((AndroidTestCase) test).setTestContext(testContext); } } Loading test-runner/android/test/TestRunner.java +5 −3 Original line number Diff line number Diff line Loading @@ -84,6 +84,7 @@ public class TestRunner implements PerformanceTestCase.Intermediates { super(); } @Override public void run(TestResult result) { result.addListener(this); super.run(result); Loading Loading @@ -337,6 +338,7 @@ public class TestRunner implements PerformanceTestCase.Intermediates { AndroidTestCase testcase = (AndroidTestCase) test; try { testcase.setContext(mContext); testcase.setTestContext(mContext); } catch (Exception ex) { Log.i("TestHarness", ex.toString()); } Loading Loading
core/java/android/test/AndroidTestCase.java +23 −3 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -54,6 +55,25 @@ public class AndroidTestCase extends TestCase { return mContext; } /** * 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} Loading
test-runner/android/test/AndroidTestRunner.java +4 −2 Original line number Diff line number Diff line Loading @@ -158,16 +158,18 @@ public class AndroidTestRunner extends BaseTestRunner { mTestResult.addListener(testListener); } Context testContext = mInstrumentation.getContext(); for (TestCase testCase : mTestCases) { setContextIfAndroidTestCase(testCase, mContext); setContextIfAndroidTestCase(testCase, mContext, testContext); setInstrumentationIfInstrumentationTestCase(testCase, mInstrumentation); testCase.run(mTestResult); } } private void setContextIfAndroidTestCase(Test test, Context context) { private void setContextIfAndroidTestCase(Test test, Context context, Context testContext) { if (AndroidTestCase.class.isAssignableFrom(test.getClass())) { ((AndroidTestCase) test).setContext(context); ((AndroidTestCase) test).setTestContext(testContext); } } Loading
test-runner/android/test/TestRunner.java +5 −3 Original line number Diff line number Diff line Loading @@ -84,6 +84,7 @@ public class TestRunner implements PerformanceTestCase.Intermediates { super(); } @Override public void run(TestResult result) { result.addListener(this); super.run(result); Loading Loading @@ -337,6 +338,7 @@ public class TestRunner implements PerformanceTestCase.Intermediates { AndroidTestCase testcase = (AndroidTestCase) test; try { testcase.setContext(mContext); testcase.setTestContext(mContext); } catch (Exception ex) { Log.i("TestHarness", ex.toString()); } Loading