Search in sources :

Example 96 with Runner

use of org.junit.runner.Runner in project android-test by android.

the class CustomRunnerBuilder method runnerForClass.

@Override
public Runner runnerForClass(Class<?> testClass) throws Throwable {
    if (Runnable.class.isAssignableFrom(testClass)) {
        final Runnable runnable = (Runnable) testClass.getDeclaredConstructor().newInstance();
        final Description description = Description.createTestDescription(testClass, "run");
        return new Runner() {

            @Override
            public Description getDescription() {
                return description;
            }

            @Override
            public void run(RunNotifier notifier) {
                EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
                eachNotifier.fireTestStarted();
                try {
                    runnable.run();
                } catch (AssumptionViolatedException e) {
                    eachNotifier.addFailedAssumption(e);
                } catch (Throwable e) {
                    eachNotifier.addFailure(e);
                } finally {
                    eachNotifier.fireTestFinished();
                }
            }
        };
    } else {
        return null;
    }
}
Also used : Runner(org.junit.runner.Runner) Description(org.junit.runner.Description) RunNotifier(org.junit.runner.notification.RunNotifier) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier)

Example 97 with Runner

use of org.junit.runner.Runner in project android-test by android.

the class TestRequestBuilder method build.

/**
 * Builds the {@link Request} based on provided data.
 *
 * @throws java.lang.IllegalArgumentException if provided set of data is not valid
 */
public Request build() {
    Trace.beginSection("build test request");
    try {
        includedPackages.removeAll(excludedPackages);
        includedClasses.removeAll(excludedClasses);
        validate(includedClasses);
        boolean scanningPath = includedClasses.isEmpty();
        // If scanning then suite methods are not supported.
        boolean ignoreSuiteMethods = this.ignoreSuiteMethods || scanningPath;
        AndroidRunnerParams runnerParams = new AndroidRunnerParams(instr, argsBundle, perTestTimeout, ignoreSuiteMethods);
        RunnerBuilder runnerBuilder = getRunnerBuilder(runnerParams);
        TestLoader loader = TestLoader.Factory.create(classLoader, runnerBuilder, scanningPath);
        Collection<String> classNames;
        if (scanningPath) {
            // no class restrictions have been specified. Load all classes.
            Log.d(TAG, "Using class path scanning to discover tests");
            classNames = getClassNamesFromClassPath();
        } else {
            Log.d(TAG, String.format("Skipping class path scanning and directly running %s", includedClasses));
            classNames = includedClasses;
        }
        List<Runner> runners = loader.getRunnersFor(classNames);
        Suite suite = ExtendedSuite.createSuite(runners);
        Request request = Request.runner(suite);
        return new LenientFilterRequest(request, filter);
    } finally {
        Trace.endSection();
    }
}
Also used : Suite(org.junit.runners.Suite) Runner(org.junit.runner.Runner) RunnerBuilder(org.junit.runners.model.RunnerBuilder) Request(org.junit.runner.Request) AndroidRunnerParams(androidx.test.internal.util.AndroidRunnerParams)

Example 98 with Runner

use of org.junit.runner.Runner in project android-test by android.

the class TestExecutorTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    when(mockRequest.getRunner()).thenReturn(new Runner() {

        @Override
        public Description getDescription() {
            return Description.EMPTY;
        }

        @Override
        public void run(RunNotifier notifier) {
        }
    });
    executor = new TestExecutor.Builder(getInstrumentation()).addRunListener(mockListener).build();
}
Also used : Runner(org.junit.runner.Runner) Description(org.junit.runner.Description) RunNotifier(org.junit.runner.notification.RunNotifier) Before(org.junit.Before)

Example 99 with Runner

use of org.junit.runner.Runner in project android-test by android.

the class TestRequestBuilderTest method testShardingFilter_Empty.

@Test
public void testShardingFilter_Empty() {
    Request request = createBuilder().addShardingFilter(97, 0).addTestClass(TestShardingFilterTest.class.getName()).build();
    Runner runner = request.getRunner();
    JUnitCore testRunner = new JUnitCore();
    Result result = testRunner.run(runner);
    Assert.assertEquals(0, result.getRunCount());
}
Also used : Runner(org.junit.runner.Runner) JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) Result(org.junit.runner.Result) TestResult(junit.framework.TestResult) FlakyTest(androidx.test.filters.FlakyTest) LargeTest(androidx.test.filters.LargeTest) SmallTest(androidx.test.filters.SmallTest) JUnit3SuiteWithTest(androidx.test.testing.fixtures.JUnit3SuiteWithTest) MediumTest(androidx.test.filters.MediumTest) SampleJUnit3Test(androidx.test.testing.fixtures.SampleJUnit3Test) Test(org.junit.Test)

Example 100 with Runner

use of org.junit.runner.Runner in project android-test by android.

the class AndroidRunnerBuilderTest method jUnit3Suite_skippedExecutionTrue_jUnit3SuitePicksJUnit38ClassRunner.

@Test
public void jUnit3Suite_skippedExecutionTrue_jUnit3SuitePicksJUnit38ClassRunner() throws Throwable {
    // mock skip execution flag to return true
    when(mockAndroidRunnerParams.isSkipExecution()).thenReturn(true);
    Runner runner = androidRunnerBuilder.runnerForClass(JUnit3Suite.class);
    assertThat(runner.getClass(), typeCompatibleWith(JUnit38ClassRunner.class));
}
Also used : JUnit38ClassRunner(androidx.test.internal.runner.junit3.JUnit38ClassRunner) Runner(org.junit.runner.Runner) JUnit38ClassRunner(androidx.test.internal.runner.junit3.JUnit38ClassRunner) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Aggregations

Runner (org.junit.runner.Runner)106 Test (org.junit.Test)39 RunNotifier (org.junit.runner.notification.RunNotifier)22 ArrayList (java.util.ArrayList)18 Description (org.junit.runner.Description)18 JUnitCore (org.junit.runner.JUnitCore)18 ParentRunner (org.junit.runners.ParentRunner)16 Request (org.junit.runner.Request)15 Result (org.junit.runner.Result)13 Filter (org.junit.runner.manipulation.Filter)12 NoTestsRemainException (org.junit.runner.manipulation.NoTestsRemainException)12 InitializationError (org.junit.runners.model.InitializationError)10 Method (java.lang.reflect.Method)9 JUnit4ParameterizedTest (androidx.test.testing.fixtures.JUnit4ParameterizedTest)7 SuiteConfiguration (org.eclipse.reddeer.junit.internal.configuration.SuiteConfiguration)7 Failure (org.junit.runner.notification.Failure)7 ErrorReportingRunner (org.junit.internal.runners.ErrorReportingRunner)6 Filterable (org.junit.runner.manipulation.Filterable)6 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)6 Field (java.lang.reflect.Field)5