类org.junit.runners.ParentRunner源码实例Demo

下面列出了怎么用org.junit.runners.ParentRunner的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: marathonv5   文件: ParallelComputer.java
private static Runner parallelize(Runner runner) {
    int nThreads = Integer.getInteger(Constants.NTHREADS, Runtime.getRuntime().availableProcessors());
    LOGGER.info("Using " + nThreads + " threads.");
    if (runner instanceof ParentRunner) {
        ((ParentRunner<?>) runner).setScheduler(new RunnerScheduler() {
            private final ExecutorService fService = Executors.newFixedThreadPool(nThreads);

            @Override
            public void schedule(Runnable childStatement) {
                fService.submit(childStatement);
            }

            @Override
            public void finished() {
                try {
                    fService.shutdown();
                    fService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
                } catch (InterruptedException e) {
                    e.printStackTrace(System.err);
                }
            }
        });
    }
    return runner;
}
 
源代码2 项目: dsl-devkit   文件: ClassRunner.java
/**
 * Initializes this runner by initializing {@link #expectedMethods} with the list of methods which are expected to be called. This is then also checked by
 * {@link #methodBlock(FrameworkMethod)} and allows identifying the first and last methods correctly.
 */
private void ensureInitialized() {
  if (expectedMethods == null) {
    try {
      final Method getChildrenMethod = ParentRunner.class.getDeclaredMethod("getFilteredChildren"); //$NON-NLS-1$
      getChildrenMethod.setAccessible(true);
      @SuppressWarnings("unchecked")
      final Collection<FrameworkMethod> testMethods = (Collection<FrameworkMethod>) getChildrenMethod.invoke(this);
      expectedMethods = ImmutableList.copyOf(Iterables.filter(testMethods, new Predicate<FrameworkMethod>() {
        @Override
        public boolean apply(final FrameworkMethod input) {
          return input.getAnnotation(Ignore.class) == null;
        }
      }));
      currentMethodIndex = 0;
      // CHECKSTYLE:OFF
    } catch (Exception e) {
      // CHECKSTYLE:ON
      throw new IllegalStateException(e);
    }
  }
}
 
源代码3 项目: buck   文件: DelegateRunNotifier.java
boolean hasJunitTimeout(Description description) {
  // Do not do apply the default timeout if the test has its own @Test(timeout).
  Test testAnnotation = description.getAnnotation(Test.class);
  if (testAnnotation != null && testAnnotation.timeout() > 0) {
    return true;
  }

  // Do not do apply the default timeout if the test has its own @Rule Timeout.
  if (runner instanceof ParentRunner) {
    return BuckBlockJUnit4ClassRunner.hasTimeoutRule(((ParentRunner) runner).getTestClass());
  }

  Class<?> clazz = description.getTestClass();
  while (clazz != null) {
    for (Field field : clazz.getFields()) {
      if (field.getAnnotationsByType(Rule.class).length > 0
          && field.getType().equals(Timeout.class)) {
        return true;
      }
    }

    clazz = clazz.getSuperclass();
  }
  return false;
}
 
源代码4 项目: vanillacore   文件: IsolatedClassLoaderSuite.java
/**
 * Sets the thread's context class loader to the class loader for the test
 * class.
 */
@Override
protected void runChild(Runner runner, RunNotifier notifier) {
	ParentRunner<?> pr = (ParentRunner<?>) runner; // test class runner
	ClassLoader cl = null;
	try {
		cl = Thread.currentThread().getContextClassLoader();
		Thread.currentThread().setContextClassLoader(
				pr.getTestClass().getJavaClass().getClassLoader());
		super.runChild(runner, notifier);
	} finally {
		Thread.currentThread().setContextClassLoader(cl);
	}
}
 
源代码5 项目: dsl-devkit   文件: FilterRegistry.java
/**
 * Initializes the test filter.
 *
 * @param parentRunner
 *          the {@link ParentRunner} to initialize, must not be {@code null}
 */
public static void initializeFilter(final ParentRunner<?> parentRunner) {
  try {
    parentRunner.filter(INSTANCE);
  } catch (NoTestsRemainException e) {
    // we ignore the case where no children are left
  }
}
 
源代码6 项目: offheap-store   文件: ParallelParameterized.java
@Override
public void setScheduler(RunnerScheduler scheduler) {
  for (Runner child : getChildren()) {
    if (child instanceof ParentRunner<?>) {
      ((ParentRunner<?>) child).setScheduler(scheduler);
    }
  }
}
 
源代码7 项目: ehcache3   文件: ParallelParameterized.java
public ParallelParameterized(Class<?> klass) throws Throwable {
  super(klass);
  setScheduler(new ExecutorScheduler(() -> newCachedThreadPool(r -> new Thread(r, "TestRunner-Thread-" + klass))));
  getChildren().forEach(child -> {
    if (child instanceof ParentRunner<?>) {
      ((ParentRunner) child).setScheduler(new ExecutorScheduler(() -> newCachedThreadPool(r -> new Thread(r, "TestRunner-Thread-" + r.toString()))));
    }
  });
}
 
源代码8 项目: burst   文件: ParentRunnerSpy.java
/**
 * Reflectively invokes a {@link ParentRunner}'s getFilteredChildren method. Manipulating this
 * list lets us control which tests will be run.
 */
static <T> List<T> getFilteredChildren(ParentRunner<T> parentRunner) {
  try {
    //noinspection unchecked
    return new ArrayList<>((Collection<T>) getFilteredChildrenMethod.invoke(parentRunner));
  } catch (IllegalAccessException | InvocationTargetException e) {
    throw new RuntimeException("Failed to invoke getFilteredChildren()", e);
  }
}
 
源代码9 项目: logging-log4j2   文件: StackLocatorTest.java
@Test
public void testGetCallerClassViaAnchorClass() throws Exception {
    final Class<?> expected = BlockJUnit4ClassRunner.class;
    final Class<?> actual = stackLocator.getCallerClass(ParentRunner.class);
    // if this test fails in the future, it's probably because of a JUnit upgrade; check the new stack trace and
    // update this test accordingly
    assertSame(expected, actual);
}
 
源代码10 项目: logging-log4j2   文件: StackLocatorUtilTest.java
@Test
public void testGetCallerClassViaAnchorClass() throws Exception {
    final Class<?> expected = BlockJUnit4ClassRunner.class;
    final Class<?> actual = StackLocatorUtil.getCallerClass(ParentRunner.class);
    // if this test fails in the future, it's probably because of a JUnit upgrade; check the new stack trace and
    // update this test accordingly
    assertSame(expected, actual);
}
 
源代码11 项目: justtestlah   文件: JustTestLahRunner.java
@Override
protected List<ParentRunner<?>> getChildren() {
  return children;
}
 
源代码12 项目: justtestlah   文件: JustTestLahRunner.java
@Override
protected Description describeChild(ParentRunner<?> child) {
  return child.getDescription();
}
 
源代码13 项目: justtestlah   文件: JustTestLahRunner.java
@Override
protected void runChild(ParentRunner<?> child, RunNotifier notifier) {
  child.run(notifier);
}
 
@Override
protected List<ParentRunner<?>> getChildren()
{
    return cucumber.getChildren();
}
 
@Override
protected Description describeChild(ParentRunner<?> child)
{
    return cucumber.describeChild(child);
}
 
@Override
protected void runChild(ParentRunner<?> child, RunNotifier notifier)
{
    cucumber.runChild(child, notifier);
}
 
源代码17 项目: senbot   文件: ParameterizedCucumber.java
@Override
protected Description describeChild(ParentRunner child) {
	return child.getDescription();
}
 
源代码18 项目: dsl-devkit   文件: SorterUtil.java
/**
 * Initializes the test sorter.
 * 
 * @param parentRunner
 *          the {@link ParentRunner} to initialize, must not be {@code null}
 */
public void initializeSorter(final ParentRunner<?> parentRunner) {
  parentRunner.sort(sorter);
}
 
源代码19 项目: dsl-devkit   文件: SorterUtil.java
/**
 * Initializes the test sorter.
 * 
 * @param parentRunner
 *          the {@link ParentRunner} to initialize, must not be {@code null}
 */
public void initializeSorter(final ParentRunner<?> parentRunner) {
  parentRunner.sort(sorter);
}
 
 类所在包
 同包方法