org.junit.runners.model.RunnerBuilder Java Examples

The following examples show how to use org.junit.runners.model.RunnerBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RunnerArgsTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
/** Test that a custom runner builder is loaded */
@Test
public void fromBundle_notRunnerBuilder() {
  Bundle b = new Bundle();
  String className = CustomTestFilter.class.getName();
  b.putString(RunnerArgs.ARGUMENT_RUNNER_BUILDER, className);
  try {
    new RunnerArgs.Builder().fromBundle(InstrumentationRegistry.getInstrumentation(), b).build();
    fail("Did not detect invalid runner builder");
  } catch (IllegalArgumentException e) {
    assertEquals(
        "Unexpected exception",
        className + " does not extend " + RunnerBuilder.class.getName(),
        e.getMessage());
  }
}
 
Example #2
Source File: FastTestsOnlySuite.java    From aws-encryption-sdk-java with Apache License 2.0 6 votes vote down vote up
public CustomRunner(Class<?> klass, RunnerBuilder builder) throws InitializationError {
    super(
            klass,
            new RunnerBuilder() {
                @Override public Runner runnerForClass(Class<?> testClass) throws Throwable {
                    Boolean oldValue = IS_FAST_TEST_SUITE_ACTIVE.get();

                    try {
                        IS_FAST_TEST_SUITE_ACTIVE.set(true);
                        Runner r = builder.runnerForClass(testClass);
                        return r;
                    } finally {
                        IS_FAST_TEST_SUITE_ACTIVE.set(oldValue);
                    }
                }
            }
    );
}
 
Example #3
Source File: AndroidRunnerBuilder.java    From android-test with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize.
 *
 * <p>Each class in the {@code customRunnerBuilderClasses} list must be a concrete public class
 * and must have a public no-argument constructor.
 *
 * @param suiteBuilder the top level {@link RunnerBuilder} to use to build nested classes.
 * @param runnerParams {@link AndroidRunnerParams} that stores common runner parameters
 * @param scanningPath true if being used to build {@link Runner} from classes found while
 *     scanning the path; requires extra checks to avoid unnecessary errors.
 * @param customRunnerBuilderClasses custom {@link RunnerBuilder} classes
 * @throws IllegalStateException if any of the custom {@link RunnerBuilder} classes cannot be
 *     instantiated.
 */
AndroidRunnerBuilder(
    RunnerBuilder suiteBuilder,
    AndroidRunnerParams runnerParams,
    boolean scanningPath,
    List<Class<? extends RunnerBuilder>> customRunnerBuilderClasses) {
  super(true);
  androidJUnit3Builder = new AndroidJUnit3Builder(runnerParams, scanningPath);
  androidJUnit4Builder = new AndroidJUnit4Builder(runnerParams, scanningPath);
  androidSuiteBuilder = new AndroidSuiteBuilder(runnerParams);
  androidAnnotatedBuilder =
      new AndroidAnnotatedBuilder(suiteBuilder == null ? this : suiteBuilder, runnerParams);
  ignoredBuilder = new IgnoredBuilder();

  customRunnerBuilders = instantiateRunnerBuilders(customRunnerBuilderClasses);
}
 
Example #4
Source File: AdaptedJUnitTestUnit.java    From pitest with Apache License 2.0 5 votes vote down vote up
public static Runner createRunner(final Class<?> clazz) {
  final RunnerBuilder builder = createRunnerBuilder();
  try {
    return builder.runnerForClass(clazz);
  } catch (final Throwable ex) {
    LOG.log(Level.SEVERE, "Error while creating runner for " + clazz, ex);
    throw translateCheckedException(ex);
  }

}
 
Example #5
Source File: ProcessBasicSuite.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public ProcessBasicSuite(final Class<?> klass,
                         final RunnerBuilder builder)
                         throws InitializationError {
    super(klass, builder, allTests, testsToEnforce, true,
          TraversalEngine.Type.STANDARD);
    RegisterUtil.registerBackends();
}
 
Example #6
Source File: CustomSuite.java    From hgraphdb with Apache License 2.0 5 votes vote down vote up
public CustomSuite(final Class<?> klass, final RunnerBuilder builder) throws InitializationError {
    super(klass, builder,
            new Class<?>[]{
                    CustomTest.class,
            },
            null,
            false,
            TraversalEngine.Type.STANDARD);
}
 
Example #7
Source File: ProcessBasicSuite.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public ProcessBasicSuite(final Class<?> klass,
                         final RunnerBuilder builder,
                         final Class<?>[] testsToExecute)
                         throws InitializationError {
    super(klass, builder, testsToExecute, testsToEnforce, true,
          TraversalEngine.Type.STANDARD);
    RegisterUtil.registerBackends();
}
 
Example #8
Source File: TitanStrategySuite.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public TitanStrategySuite(final Class<?> klass, final RunnerBuilder builder) throws InitializationError {

        super(klass, builder,
                new Class<?>[]{
                        TitanGraphStepStrategyTest.class
                }, new Class<?>[]{
                        TitanGraphStepStrategyTest.class
                },
                false,
                TraversalEngine.Type.STANDARD);
    }
 
Example #9
Source File: AbstractGremlinSuite.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a Gremlin Test Suite implementation.
 *
 * @param klass               Required for JUnit Suite construction
 * @param builder             Required for JUnit Suite construction
 * @param testsToExecute      The list of tests to execute
 * @param testsToEnforce      The list of tests to "enforce" such that a check is made to ensure that in this list,
 *                            there exists an implementation in the testsToExecute (use {@code null} for no
 *                            enforcement).
 * @param gremlinFlavorSuite  Ignore validation of {@link Graph.OptIn} annotations which is typically reserved for structure tests
 * @param traversalEngineType The {@link TraversalEngine.Type} to enforce on this suite
 */
public AbstractGremlinSuite(final Class<?> klass, final RunnerBuilder builder, final Class<?>[] testsToExecute,
                            final Class<?>[] testsToEnforce, final boolean gremlinFlavorSuite,
                            final TraversalEngine.Type traversalEngineType) throws InitializationError {
    super(builder, klass, enforce(testsToExecute, testsToEnforce));

    this.gremlinFlavorSuite = gremlinFlavorSuite;

    // figures out what the implementer assigned as the GraphProvider class and make it available to tests.
    // the klass is the Suite that implements this suite (e.g. GroovyTinkerGraphProcessStandardTest).
    // this class should be annotated with GraphProviderClass.  Failure to do so will toss an InitializationError
    final Pair<Class<? extends GraphProvider>, Class<? extends Graph>> pair = getGraphProviderClass(klass);

    // the GraphProvider.Descriptor is only needed right now if the test if for a computer engine - an
    // exception is thrown if it isn't present.
    final Optional<GraphProvider.Descriptor> graphProviderDescriptor = getGraphProviderDescriptor(traversalEngineType, pair.getValue0());

    // validate public acknowledgement of the test suite and filter out tests ignored by the implementation
    validateOptInToSuite(pair.getValue1());
    validateOptInAndOutAnnotations(pair.getValue0());
    validateOptInAndOutAnnotations(pair.getValue1());

    registerOptOuts(pair.getValue0(), graphProviderDescriptor, traversalEngineType);
    registerOptOuts(pair.getValue1(), graphProviderDescriptor, traversalEngineType);

    try {
        final GraphProvider graphProvider = pair.getValue0().newInstance();
        GraphManager.setGraphProvider(graphProvider);
        GraphManager.setTraversalEngineType(traversalEngineType);
    } catch (Exception ex) {
        throw new InitializationError(ex);
    }
}
 
Example #10
Source File: NativeNeo4jSuite.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public NativeNeo4jSuite(final Class<?> klass, final RunnerBuilder builder) throws InitializationError {
    super(klass, builder,
            new Class<?>[]{
                    NativeNeo4jStructureCheck.class,
                    NativeNeo4jIndexCheck.class,
                    NativeNeo4jCypherCheck.class,
            }, new Class<?>[]{
                    NativeNeo4jStructureCheck.class,
                    NativeNeo4jIndexCheck.class,
                    NativeNeo4jCypherCheck.class
            },
            false,
            TraversalEngine.Type.STANDARD);
}
 
Example #11
Source File: TestRequestBuilder.java    From android-test with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the {@link Request} based on provided data.
 *
 * @throws java.lang.IllegalArgumentException if provided set of data is not valid
 */
public Request build() {
  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, scanningPath);

  TestLoader loader = TestLoader.testLoader(classLoader, runnerBuilder, scanningPath);
  Collection<String> classNames;
  if (scanningPath) {
    // no class restrictions have been specified. Load all classes.
    classNames = getClassNamesFromClassPath();
  } else {
    classNames = includedClasses;
  }

  List<Runner> runners = loader.getRunnersFor(classNames, scanningPath);

  Suite suite = ExtendedSuite.createSuite(runners);
  Request request = Request.runner(suite);
  return new LenientFilterRequest(request, filter);
}
 
Example #12
Source File: AndroidLogOnlyBuilder.java    From android-test with Apache License 2.0 5 votes vote down vote up
/**
 * @param runnerParams {@link AndroidRunnerParams} that stores common runner parameters
 * @param scanningPath true if being used to build {@link Runner} from classes found while
 *     scanning the path; requires extra checks to avoid unnecessary errors.
 */
AndroidLogOnlyBuilder(
    AndroidRunnerParams runnerParams,
    boolean scanningPath,
    List<Class<? extends RunnerBuilder>> customRunnerBuilderClasses) {
  this.runnerParams = checkNotNull(runnerParams, "runnerParams cannot be null!");
  this.scanningPath = scanningPath;

  // Create a builder for creating the executable Runner instances to wrap. Pass in this
  // builder as the suiteBuilder so that this will be called to create Runners for nested
  // classes, e.g. in Suite or Enclosed.
  builder =
      new AndroidRunnerBuilder(this, runnerParams, scanningPath, customRunnerBuilderClasses);
}
 
Example #13
Source File: TestLoader.java    From android-test with Apache License 2.0 5 votes vote down vote up
static TestLoader testLoader(
    ClassLoader classLoader, RunnerBuilder runnerBuilder, boolean scanningPath) {
  // If scanning then wrap the supplied RunnerBuilder with one that will ignore abstract
  // classes.
  if (scanningPath) {
    runnerBuilder = new ScanningRunnerBuilder(runnerBuilder);
  }

  if (null == classLoader) {
    classLoader = TestLoader.class.getClassLoader();
  }

  return new TestLoader(classLoader, runnerBuilder);
}
 
Example #14
Source File: AndroidRunnerBuilder.java    From android-test with Apache License 2.0 5 votes vote down vote up
/**
 * @param runnerParams {@link AndroidRunnerParams} that stores common runner parameters
 * @param scanningPath true if being used to build {@link Runner} from classes found while
 *     scanning the path; requires extra checks to avoid unnecessary errors.
 * @param customRunnerBuilderClasses custom {@link RunnerBuilder} classes
 */
AndroidRunnerBuilder(
    AndroidRunnerParams runnerParams,
    boolean scanningPath,
    List<Class<? extends RunnerBuilder>> customRunnerBuilderClasses) {
  this(null, runnerParams, scanningPath, customRunnerBuilderClasses);
}
 
Example #15
Source File: AndroidLogOnlyBuilderTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Before
public void initBuilder() {
  MockitoAnnotations.initMocks(this);
  androidLogOnlyBuilder =
      new AndroidLogOnlyBuilder(
          mockAndroidRunnerParams,
          scanningPath,
          Collections.<Class<? extends RunnerBuilder>>emptyList());
}
 
Example #16
Source File: TestRequestBuilder.java    From android-test with Apache License 2.0 5 votes vote down vote up
/**
 * Get the {@link RunnerBuilder} to use to create the {@link Runner} instances.
 *
 * @param runnerParams {@link AndroidRunnerParams} that stores common runner parameters
 * @param scanningPath true if being used to build {@link Runner} from classes found while
 *     scanning the path; requires extra checks to avoid unnecessary errors.
 * @return a {@link RunnerBuilder}.
 */
private RunnerBuilder getRunnerBuilder(AndroidRunnerParams runnerParams, boolean scanningPath) {
  RunnerBuilder builder;
  if (skipExecution) {
    // If all that is needed is the list of tests then replace the Runner which will
    // run the test with one that will simply fire events for each of the tests.
    builder = new AndroidLogOnlyBuilder(runnerParams, scanningPath, customRunnerBuilderClasses);
  } else {
    builder = new AndroidRunnerBuilder(runnerParams, scanningPath, customRunnerBuilderClasses);
  }
  return builder;
}
 
Example #17
Source File: StructureBasicSuite.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public StructureBasicSuite(final Class<?> klass,
                           final RunnerBuilder builder)
                           throws InitializationError,
                                  ConfigurationException {
    super(klass, builder, allTests, null, true,
          TraversalEngine.Type.STANDARD);

    RegisterUtil.registerBackends();
}
 
Example #18
Source File: RunnerArgsTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
/** Test that a custom runner builder is loaded */
@Test
public void fromBundle_customRunnerBuilder() {
  Bundle b = new Bundle();
  b.putString(RunnerArgs.ARGUMENT_RUNNER_BUILDER, CustomRunnerBuilder.class.getName());
  RunnerArgs args =
      new RunnerArgs.Builder()
          .fromBundle(InstrumentationRegistry.getInstrumentation(), b)
          .build();
  assertEquals(
      "Mismatch in number of runner builders loaded", 1, args.runnerBuilderClasses.size());
  Class<? extends RunnerBuilder> runnerBuilderClass = args.runnerBuilderClasses.get(0);
  assertTrue(
      "RunnerBuilder not of correct type", runnerBuilderClass == CustomRunnerBuilder.class);
}
 
Example #19
Source File: TestLoaderTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  AndroidRunnerParams runnerParams = new AndroidRunnerParams(null, null, -1, false);
  AndroidRunnerBuilder runnerBuilder =
      new AndroidRunnerBuilder(
          runnerParams, scanningPath, Collections.<Class<? extends RunnerBuilder>>emptyList());
  loader = TestLoader.testLoader(null, runnerBuilder, scanningPath);
}
 
Example #20
Source File: TestsInPkgSuite.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public TestsInPkgSuite(Class<?> klass, RunnerBuilder builder) throws InitializationError {
    super(builder, klass, getPkgTestClasses(klass));
}
 
Example #21
Source File: AndroidRunnerBuilder.java    From android-test with Apache License 2.0 4 votes vote down vote up
@Override
protected RunnerBuilder suiteMethodBuilder() {
  return androidSuiteBuilder;
}
 
Example #22
Source File: BonitaSuite.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public BonitaSuite(RunnerBuilder builder, Class<?>[] classes) throws InitializationError {
    super(builder, classes);
}
 
Example #23
Source File: ParallelComputer.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@Override
protected Runner getRunner(RunnerBuilder builder, Class<?> testClass) throws Throwable {
    Runner runner = super.getRunner(builder, testClass);
    return fMethods ? parallelize(runner) : runner;
}
 
Example #24
Source File: SeleniumSuite.java    From olat with Apache License 2.0 4 votes vote down vote up
public SeleniumSuite(RunnerBuilder builder, Class<?> klass, Class<?>[] suiteClasses) throws InitializationError {
    super(builder, klass, suiteClasses);
}
 
Example #25
Source File: SeleniumSuite.java    From olat with Apache License 2.0 4 votes vote down vote up
public SeleniumSuite(RunnerBuilder builder, Class<?>[] classes) throws InitializationError {
    super(builder, classes);
}
 
Example #26
Source File: SeleniumSuite.java    From olat with Apache License 2.0 4 votes vote down vote up
public SeleniumSuite(Class<?> klass, RunnerBuilder builder) throws InitializationError {
    super(klass, builder);
}
 
Example #27
Source File: SeleniumSuite.java    From olat with Apache License 2.0 4 votes vote down vote up
public SeleniumSuite(RunnerBuilder builder, Class<?> klass, Class<?>[] suiteClasses) throws InitializationError {
    super(builder, klass, suiteClasses);
}
 
Example #28
Source File: SeleniumSuite.java    From olat with Apache License 2.0 4 votes vote down vote up
public SeleniumSuite(RunnerBuilder builder, Class<?>[] classes) throws InitializationError {
    super(builder, classes);
}
 
Example #29
Source File: SmokeTestSuite.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
public SmokeTestSuite(Class<?> clazz, RunnerBuilder builder) throws InitializationError {
  super(clazz);
  this.runners = builder.runners(clazz, getTestClasses());
}
 
Example #30
Source File: JavascriptExpressionSuite.java    From joinery with GNU General Public License v3.0 4 votes vote down vote up
public JavascriptExpressionSuite(final Class<?> cls, final RunnerBuilder builder)
throws InitializationError, IOException {
    super(cls, runnersFromJs(cls));
}