本文整理汇总了Java中org.junit.runners.ParentRunner类的典型用法代码示例。如果您正苦于以下问题:Java ParentRunner类的具体用法?Java ParentRunner怎么用?Java ParentRunner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParentRunner类属于org.junit.runners包,在下文中一共展示了ParentRunner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parallelize
import org.junit.runners.ParentRunner; //导入依赖的package包/类
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: ensureInitialized
import org.junit.runners.ParentRunner; //导入依赖的package包/类
/**
* 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: getDescription
import org.junit.runners.ParentRunner; //导入依赖的package包/类
public Description getDescription() {
Description description = Description.createSuiteDescription(myName, getTestClass().getAnnotations());
try {
final Method getFilteredChildrenMethod = ParentRunner.class.getDeclaredMethod("getFilteredChildren", new Class[0]);
getFilteredChildrenMethod.setAccessible(true);
Collection filteredChildren = (Collection)getFilteredChildrenMethod.invoke(this, new Object[0]);
for (Iterator iterator = filteredChildren.iterator(); iterator.hasNext();) {
Object child = iterator.next();
description.addChild(describeChild((Runner)child));
}
}
catch (Exception e) {
e.printStackTrace();
}
return description;
}
示例4: makeLink
import org.junit.runners.ParentRunner; //导入依赖的package包/类
public ParentRunner<?> makeLink(Class<? extends ParentRunner<?>> runnerClass, final Class<?> testClass,
final CompositeRunner compositeRunner, final ParentRunner<?> nextRunner,
boolean isTestStructureProvider) throws InitializationError {
ClassPool pool = ClassPool.getDefault();
String newClassName = runnerClass.getName() + (isTestStructureProvider ? "TestStructureProvider" : "ChainLink");
final Class<?> newRunnerCtClass = makeLinkClass(pool, newClassName, runnerClass, isTestStructureProvider);
try {
return (ParentRunner<?>) new ReflectiveCallable() {
@Override
protected Object runReflectiveCall() throws Throwable {
return newRunnerCtClass.getConstructor(Class.class, CompositeRunner.class, ParentRunner.class)
.newInstance(testClass, compositeRunner, nextRunner);
}
}.run();
} catch (InitializationError e) {
throw e;
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
}
示例5: buildFeatureElementRunners
import org.junit.runners.ParentRunner; //导入依赖的package包/类
private void buildFeatureElementRunners() {
for (CucumberTagStatement cucumberTagStatement : cucumberFeature
.getFeatureElements()) {
try {
ParentRunner<?> featureElementRunner;
if (cucumberTagStatement instanceof CucumberScenario) {
featureElementRunner =
new RestExecutionUnitRunner(runtime, cucumberTagStatement,
jUnitReporter, cucumberFeature);
} else {
featureElementRunner =
new RestScenarioOutlineRunner(runtime,
(CucumberScenarioOutline) cucumberTagStatement, jUnitReporter,
cucumberFeature);
}
children.add(featureElementRunner);
} catch (InitializationError e) {
throw new CucumberException("Failed to create scenario runner", e);
}
}
}
示例6: parallelize
import org.junit.runners.ParentRunner; //导入依赖的package包/类
private static Runner parallelize(Runner runner) {
if (runner instanceof ParentRunner) {
((ParentRunner<?>) runner).setScheduler(new RunnerScheduler() {
private final ExecutorService fService = Executors.newCachedThreadPool();
public void schedule(Runnable childStatement) {
fService.submit(childStatement);
}
public void finished() {
try {
fService.shutdown();
fService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
e.printStackTrace(System.err);
}
}
});
}
return runner;
}
示例7: useChildHarvester
import org.junit.runners.ParentRunner; //导入依赖的package包/类
@Test
public void useChildHarvester() throws InitializationError {
log = "";
ParentRunner<?> runner = new BlockJUnit4ClassRunner(FruitTest.class);
runner.setScheduler(new RunnerScheduler() {
public void schedule(Runnable childStatement) {
log += "before ";
childStatement.run();
log += "after ";
}
public void finished() {
log += "afterAll ";
}
});
runner.run(new RunNotifier());
assertEquals("before apple after before banana after afterAll ", log);
}
示例8: noBeforeOnClasspath
import org.junit.runners.ParentRunner; //导入依赖的package包/类
@Test
public void noBeforeOnClasspath() throws Exception {
File libJar = tempFolder.newFile("lib.jar");
try (FileOutputStream fis = new FileOutputStream(libJar);
JarOutputStream jos = new JarOutputStream(fis)) {
addClassToJar(jos, RunWith.class);
addClassToJar(jos, JUnit4.class);
addClassToJar(jos, BlockJUnit4ClassRunner.class);
addClassToJar(jos, ParentRunner.class);
addClassToJar(jos, SuperTest.class);
addClassToJar(jos, SuperTest.class.getEnclosingClass());
}
compilationHelper
.addSourceLines(
"Test.java",
"import org.junit.runner.RunWith;",
"import org.junit.runners.JUnit4;",
"import " + SuperTest.class.getCanonicalName() + ";",
"@RunWith(JUnit4.class)",
"class Test extends SuperTest {",
" @Override public void setUp() {}",
"}")
.setArgs(Arrays.asList("-cp", libJar.toString()))
.doTest();
}
示例9: getDescription
import org.junit.runners.ParentRunner; //导入依赖的package包/类
public Description getDescription() {
Description description = Description.createSuiteDescription(myName, getTestClass().getAnnotations());
try {
final Method getFilteredChildrenMethod = ParentRunner.class.getDeclaredMethod("getFilteredChildren", new Class[0]);
getFilteredChildrenMethod.setAccessible(true);
List filteredChildren = (List)getFilteredChildrenMethod.invoke(this, new Object[0]);
for (int i = 0, filteredChildrenSize = filteredChildren.size(); i < filteredChildrenSize; i++) {
Object child = filteredChildren.get(i);
description.addChild(describeChild((Runner)child));
}
}
catch (Exception e) {
e.printStackTrace();
}
return description;
}
示例10: getChildren
import org.junit.runners.ParentRunner; //导入依赖的package包/类
@Override
protected List getChildren() {
try {
Method method = ParentRunner.class.getDeclaredMethod("getChildren");
method.setAccessible(true);
return (List) method.invoke(oleasterRobolectricRunner);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return new ArrayList();
}
示例11: describeChild
import org.junit.runners.ParentRunner; //导入依赖的package包/类
@Override
protected Description describeChild(Object object) {
try {
Method method = ParentRunner.class.getDeclaredMethod("describeChild", Object.class);
method.setAccessible(true);
return (Description) method.invoke(oleasterRobolectricRunner, object);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return Description.EMPTY;
}
示例12: runChild
import org.junit.runners.ParentRunner; //导入依赖的package包/类
@Override
protected void runChild(Object object, RunNotifier runNotifier) {
try {
Method method = ParentRunner.class.getDeclaredMethod("runChild", Object.class, RunNotifier.class);
method.setAccessible(true);
method.invoke(oleasterRobolectricRunner, object, runNotifier);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
示例13: parallelSchedulerTest
import org.junit.runners.ParentRunner; //导入依赖的package包/类
@Test
public void parallelSchedulerTest() throws Throwable {
ParallelParameterized parallelParameterized = new ParallelParameterized(FibonacciTest.class);
Class<?> clazz = parallelParameterized.getClass();
while (clazz != ParentRunner.class) {
clazz = clazz.getSuperclass();
}
Field schedulerField = clazz.getDeclaredField("scheduler");
schedulerField.setAccessible(true);
assertTrue(schedulerField.get(parallelParameterized) instanceof ParallelScheduler);
}
示例14: runChild
import org.junit.runners.ParentRunner; //导入依赖的package包/类
/**
* 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);
}
}
示例15: initializeFilter
import org.junit.runners.ParentRunner; //导入依赖的package包/类
/**
* 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
}
}