Methods Summary |
---|
private void | assertContentsInOrder(java.util.List actual, android.test.suitebuilder.ListTestCaseNames.TestDescriptor source)
TestDescriptor[] clonedSource = source.clone();
assertEquals("Unexpected number of items.", clonedSource.length, actual.size());
for (int i = 0; i < actual.size(); i++) {
TestDescriptor actualItem = actual.get(i);
TestDescriptor sourceItem = clonedSource[i];
assertEquals("Unexpected item. Index: " + i, sourceItem, actualItem);
}
|
private void | assertTestRunnerCalledWithExpectedParameters(java.lang.String expectedTestClassName, java.lang.String expectedTestMethodName)
Test test = mStubAndroidTestRunner.getTest();
assertContentsInOrder(ListTestCaseNames.getTestNames((TestSuite) test),
new TestDescriptor(expectedTestClassName, expectedTestMethodName));
assertTrue(mInstrumentationTestRunner.isStarted());
assertFalse(mInstrumentationTestRunner.isFinished());
|
private android.os.Bundle | createBundle(java.lang.String key, java.lang.String value)
Bundle bundle = new Bundle();
bundle.putString(key, value);
return bundle;
|
protected void | setUp()
super.setUp();
mStubAndroidTestRunner = new StubAndroidTestRunner();
mTargetContextPackageName = "android.test.suitebuilder.examples";
mInstrumentationTestRunner = new StubInstrumentationTestRunner(
new StubContext("com.google.foo.tests"),
new StubContext(mTargetContextPackageName), mStubAndroidTestRunner);
|
public void | testAnnotationParameter()Test that the -e {@link InstrumentationTestRunner.ARGUMENT_ANNOTATION} parameter properly
selects tests.
String expectedTestClassName = AnnotationTest.class.getName();
Bundle args = new Bundle();
args.putString(InstrumentationTestRunner.ARGUMENT_TEST_CLASS, expectedTestClassName);
args.putString(InstrumentationTestRunner.ARGUMENT_ANNOTATION, FlakyTest.class.getName());
mInstrumentationTestRunner.onCreate(args);
assertTestRunnerCalledWithExpectedParameters(expectedTestClassName, "testAnnotated");
|
public void | testBadMethodArgument()Test that specifying a method which does not exist is handled gracefully
String testClassName = PlaceHolderTest.class.getName();
String invalidMethodName = "testNoExist";
String classAndMethod = testClassName + "#" + invalidMethodName;
mInstrumentationTestRunner.onCreate(createBundle(
InstrumentationTestRunner.ARGUMENT_TEST_CLASS, classAndMethod));
assertTestRunnerCalledWithExpectedParameters(testClassName,
invalidMethodName);
|
public void | testDelayParameter()
int delayMsec = 1000;
Bundle args = new Bundle();
args.putInt(InstrumentationTestRunner.ARGUMENT_DELAY_MSEC, delayMsec);
args.putString(InstrumentationTestRunner.ARGUMENT_TEST_CLASS,
PlaceHolderTest.class.getName() + "," +
PlaceHolderTest2.class.getName());
mInstrumentationTestRunner.onCreate(args);
Thread t = new Thread() { public void run() { mInstrumentationTestRunner.onStart(); } };
// Should delay three times: before, between, and after the two tests.
long beforeTest = System.currentTimeMillis();
t.start();
t.join();
assertTrue(System.currentTimeMillis() > beforeTest + delayMsec * 3);
assertTrue(mInstrumentationTestRunner.isStarted());
assertTrue(mInstrumentationTestRunner.isFinished());
assertTrue(mStubAndroidTestRunner.isRun());
|
public void | testMultipleTestClass()
String classArg = PlaceHolderTest.class.getName() + "," +
PlaceHolderTest2.class.getName();
mInstrumentationTestRunner.onCreate(createBundle(
InstrumentationTestRunner.ARGUMENT_TEST_CLASS, classArg));
Test test = mStubAndroidTestRunner.getTest();
assertContentsInOrder(ListTestCaseNames.getTestNames((TestSuite) test),
new TestDescriptor(PlaceHolderTest.class.getName(), "testPlaceHolder"),
new TestDescriptor(PlaceHolderTest2.class.getName(), "testPlaceHolder2"));
|
public void | testNotAnnotationParameter()Test that the -e {@link InstrumentationTestRunner.ARGUMENT_NOT_ANNOTATION} parameter
properly excludes tests.
String expectedTestClassName = AnnotationTest.class.getName();
Bundle args = new Bundle();
args.putString(InstrumentationTestRunner.ARGUMENT_TEST_CLASS, expectedTestClassName);
args.putString(InstrumentationTestRunner.ARGUMENT_NOT_ANNOTATION,
FlakyTest.class.getName());
mInstrumentationTestRunner.onCreate(args);
assertTestRunnerCalledWithExpectedParameters(expectedTestClassName, "testNotAnnotated");
|
public void | testOverrideTestToRunWithClassAndMethodArgument()
String expectedTestClassName = PlaceHolderTest.class.getName();
String expectedTestMethodName = "testPlaceHolder";
String classAndMethod = expectedTestClassName + "#" + expectedTestMethodName;
mInstrumentationTestRunner.onCreate(createBundle(
InstrumentationTestRunner.ARGUMENT_TEST_CLASS, classAndMethod));
assertTestRunnerCalledWithExpectedParameters(expectedTestClassName,
expectedTestMethodName);
|
public void | testOverrideTestToRunWithClassArgument()
String expectedTestClassName = PlaceHolderTest.class.getName();
mInstrumentationTestRunner.onCreate(createBundle(
InstrumentationTestRunner.ARGUMENT_TEST_CLASS, expectedTestClassName));
assertTestRunnerCalledWithExpectedParameters(expectedTestClassName, "testPlaceHolder");
|
public void | testUnhandledException()Test that runtime exceptions during runTest are handled gracefully
StubAndroidTestRunner stubAndroidTestRunner = new StubAndroidTestRunner() {
@Override
public void runTest() {
throw new RuntimeException();
}
};
StubInstrumentationTestRunner instrumentationTestRunner = new StubInstrumentationTestRunner(
new StubContext("com.google.foo.tests"),
new StubContext(mTargetContextPackageName), stubAndroidTestRunner);
instrumentationTestRunner.onCreate(new Bundle());
instrumentationTestRunner.onStart();
assertTrue("Instrumentation did not finish", instrumentationTestRunner.isFinished());
// ensure a meaningful error message placed in results
String resultsData = instrumentationTestRunner.mResults.getString(
Instrumentation.REPORT_KEY_STREAMRESULT);
assertTrue("Instrumentation results is missing RuntimeException",
resultsData.contains("RuntimeException"));
|
public void | testUseSelfAsTestSuiteProviderWhenNoMetaDataOrClassArgument()
TestSuite testSuite = new TestSuite();
testSuite.addTestSuite(PlaceHolderTest.class);
mInstrumentationTestRunner.setAllTestsSuite(testSuite);
mInstrumentationTestRunner.onCreate(null);
assertTestRunnerCalledWithExpectedParameters(
PlaceHolderTest.class.getName(), "testPlaceHolder");
|