Search in sources :

Example 11 with TestMethod

use of android.test.suitebuilder.TestMethod in project platform_frameworks_base by android.

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 12 with TestMethod

use of android.test.suitebuilder.TestMethod in project platform_frameworks_base by android.

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 13 with TestMethod

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

the class InstrumentationCoreTestRunner method getBuilderRequirements.

@Override
List<Predicate<TestMethod>> getBuilderRequirements() {
    List<Predicate<TestMethod>> builderRequirements = super.getBuilderRequirements();
    Predicate<TestMethod> brokenTestPredicate = Predicates.not(new HasAnnotation(BrokenTest.class));
    builderRequirements.add(brokenTestPredicate);
    if (!singleTest) {
        Predicate<TestMethod> sideEffectPredicate = Predicates.not(new HasAnnotation(SideEffect.class));
        builderRequirements.add(sideEffectPredicate);
    }
    return builderRequirements;
}
Also used : BrokenTest(dalvik.annotation.BrokenTest) HasAnnotation(android.test.suitebuilder.annotation.HasAnnotation) TestMethod(android.test.suitebuilder.TestMethod) Predicate(com.android.internal.util.Predicate) SideEffect(dalvik.annotation.SideEffect)

Example 14 with TestMethod

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

the class HasClassAnnotationTest method classHasAnnotation.

private boolean classHasAnnotation(Class<? extends TestCase> aClass, Class<Smoke> expectedClassification) throws NoSuchMethodException {
    Method method = aClass.getMethod("testSomeTest");
    TestMethod testMethod = new TestMethod(method, aClass);
    return new HasClassAnnotation(expectedClassification).apply(testMethod);
}
Also used : TestMethod(android.test.suitebuilder.TestMethod) Method(java.lang.reflect.Method) TestMethod(android.test.suitebuilder.TestMethod)

Example 15 with TestMethod

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

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)

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