Search in sources :

Example 1 with TestMethod

use of android.test.suitebuilder.TestMethod in project android_frameworks_base by ParanoidAndroid.

the class InstrumentationTestRunner method onCreate.

@Override
public void onCreate(Bundle arguments) {
    super.onCreate(arguments);
    mArguments = arguments;
    // Apk paths used to search for test classes when using TestSuiteBuilders.
    String[] apkPaths = { getTargetContext().getPackageCodePath(), getContext().getPackageCodePath() };
    ClassPathPackageInfoSource.setApkPaths(apkPaths);
    Predicate<TestMethod> testSizePredicate = null;
    Predicate<TestMethod> testAnnotationPredicate = null;
    Predicate<TestMethod> testNotAnnotationPredicate = null;
    String testClassesArg = null;
    boolean logOnly = false;
    if (arguments != null) {
        // Test class name passed as an argument should override any meta-data declaration.
        testClassesArg = arguments.getString(ARGUMENT_TEST_CLASS);
        mDebug = getBooleanArgument(arguments, "debug");
        mJustCount = getBooleanArgument(arguments, "count");
        mSuiteAssignmentMode = getBooleanArgument(arguments, "suiteAssignment");
        mPackageOfTests = arguments.getString(ARGUMENT_TEST_PACKAGE);
        testSizePredicate = getSizePredicateFromArg(arguments.getString(ARGUMENT_TEST_SIZE_PREDICATE));
        testAnnotationPredicate = getAnnotationPredicate(arguments.getString(ARGUMENT_ANNOTATION));
        testNotAnnotationPredicate = getNotAnnotationPredicate(arguments.getString(ARGUMENT_NOT_ANNOTATION));
        logOnly = getBooleanArgument(arguments, ARGUMENT_LOG_ONLY);
        mCoverage = getBooleanArgument(arguments, "coverage");
        mCoverageFilePath = arguments.getString("coverageFile");
        try {
            // Accept either string or int
            Object delay = arguments.get(ARGUMENT_DELAY_MSEC);
            if (delay != null)
                mDelayMsec = Integer.parseInt(delay.toString());
        } catch (NumberFormatException e) {
            Log.e(LOG_TAG, "Invalid delay_msec parameter", e);
        }
    }
    TestSuiteBuilder testSuiteBuilder = new TestSuiteBuilder(getClass().getName(), getTargetContext().getClassLoader());
    if (testSizePredicate != null) {
        testSuiteBuilder.addRequirements(testSizePredicate);
    }
    if (testAnnotationPredicate != null) {
        testSuiteBuilder.addRequirements(testAnnotationPredicate);
    }
    if (testNotAnnotationPredicate != null) {
        testSuiteBuilder.addRequirements(testNotAnnotationPredicate);
    }
    if (testClassesArg == null) {
        if (mPackageOfTests != null) {
            testSuiteBuilder.includePackages(mPackageOfTests);
        } else {
            TestSuite testSuite = getTestSuite();
            if (testSuite != null) {
                testSuiteBuilder.addTestSuite(testSuite);
            } else {
                // no package or class bundle arguments were supplied, and no test suite
                // provided so add all tests in application
                testSuiteBuilder.includePackages("");
            }
        }
    } else {
        parseTestClasses(testClassesArg, testSuiteBuilder);
    }
    testSuiteBuilder.addRequirements(getBuilderRequirements());
    mTestRunner = getAndroidTestRunner();
    mTestRunner.setContext(getTargetContext());
    mTestRunner.setInstrumentation(this);
    mTestRunner.setSkipExecution(logOnly);
    mTestRunner.setTest(testSuiteBuilder.build());
    mTestCount = mTestRunner.getTestCases().size();
    if (mSuiteAssignmentMode) {
        mTestRunner.addTestListener(new SuiteAssignmentPrinter());
    } else {
        WatcherResultPrinter resultPrinter = new WatcherResultPrinter(mTestCount);
        mTestRunner.addTestListener(new TestPrinter("TestRunner", false));
        mTestRunner.addTestListener(resultPrinter);
        mTestRunner.setPerformanceResultsWriter(resultPrinter);
    }
    start();
}
Also used : TestSuiteBuilder(android.test.suitebuilder.TestSuiteBuilder) TestSuite(junit.framework.TestSuite) TestMethod(android.test.suitebuilder.TestMethod)

Example 2 with TestMethod

use of android.test.suitebuilder.TestMethod in project android_frameworks_base by ParanoidAndroid.

the class HasMethodAnnotationTest method methodHasAnnotation.

private boolean methodHasAnnotation(Class<? extends TestCase> aClass, String methodName, Class<? extends Annotation> expectedClassification) throws NoSuchMethodException {
    Method method = aClass.getMethod(methodName);
    TestMethod testMethod = new TestMethod(method, aClass);
    return new HasMethodAnnotation(expectedClassification).apply(testMethod);
}
Also used : TestMethod(android.test.suitebuilder.TestMethod) Method(java.lang.reflect.Method) TestMethod(android.test.suitebuilder.TestMethod)

Example 3 with TestMethod

use of android.test.suitebuilder.TestMethod in project android_frameworks_base by ParanoidAndroid.

the class HasAnnotationTest method hasExampleAnnotation.

private boolean hasExampleAnnotation(Class<? extends TestCase> aClass, String methodName) throws NoSuchMethodException {
    Method method = aClass.getMethod(methodName);
    TestMethod testMethod = new TestMethod(method, aClass);
    return new HasAnnotation(Example.class).apply(testMethod);
}
Also used : TestMethod(android.test.suitebuilder.TestMethod) Method(java.lang.reflect.Method) TestMethod(android.test.suitebuilder.TestMethod)

Example 4 with TestMethod

use of android.test.suitebuilder.TestMethod in project android_frameworks_base by DirtyUnicorns.

the class HasMethodAnnotationTest method methodHasAnnotation.

private boolean methodHasAnnotation(Class<? extends TestCase> aClass, String methodName, Class<? extends Annotation> expectedClassification) throws NoSuchMethodException {
    Method method = aClass.getMethod(methodName);
    TestMethod testMethod = new TestMethod(method, aClass);
    return new HasMethodAnnotation(expectedClassification).apply(testMethod);
}
Also used : TestMethod(android.test.suitebuilder.TestMethod) Method(java.lang.reflect.Method) TestMethod(android.test.suitebuilder.TestMethod)

Example 5 with TestMethod

use of android.test.suitebuilder.TestMethod in project android_frameworks_base by DirtyUnicorns.

the class HasAnnotationTest method hasExampleAnnotation.

private boolean hasExampleAnnotation(Class<? extends TestCase> aClass, String methodName) throws NoSuchMethodException {
    Method method = aClass.getMethod(methodName);
    TestMethod testMethod = new TestMethod(method, aClass);
    return new HasAnnotation(Example.class).apply(testMethod);
}
Also used : TestMethod(android.test.suitebuilder.TestMethod) Method(java.lang.reflect.Method) TestMethod(android.test.suitebuilder.TestMethod)

Aggregations

TestMethod (android.test.suitebuilder.TestMethod)21 Method (java.lang.reflect.Method)15 TestSuiteBuilder (android.test.suitebuilder.TestSuiteBuilder)5 TestSuite (junit.framework.TestSuite)5 HasAnnotation (android.test.suitebuilder.annotation.HasAnnotation)1 Predicate (com.android.internal.util.Predicate)1 BrokenTest (dalvik.annotation.BrokenTest)1 SideEffect (dalvik.annotation.SideEffect)1