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;
}
}
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();
}
}
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();
}
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());
}
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));
}
Aggregations