當前位置: 首頁>>代碼示例>>Java>>正文


Java ParentRunner類代碼示例

本文整理匯總了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;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:24,代碼來源:ParallelComputer.java

示例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);
    }
  }
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:26,代碼來源:ClassRunner.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:IdeaSuite.java

示例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);
    }
}
 
開發者ID:diosmosis,項目名稱:junit-composite-runner,代碼行數:23,代碼來源:RunnerChainLinkFactory.java

示例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);
      }
   }
}
 
開發者ID:LiamHayes1,項目名稱:rest-cucumber,代碼行數:22,代碼來源:RestFeatureRunner.java

示例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;
}
 
開發者ID:DIVERSIFY-project,項目名稱:sosiefier,代碼行數:22,代碼來源:ParallelComputer.java

示例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);
}
 
開發者ID:DIVERSIFY-project,項目名稱:sosiefier,代碼行數:20,代碼來源:ParentRunnerTest.java

示例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();
}
 
開發者ID:google,項目名稱:error-prone,代碼行數:26,代碼來源:JUnit4SetUpNotRunTest.java

示例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;
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:17,代碼來源:IdeaSuite.java

示例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();
}
 
開發者ID:bangarharshit,項目名稱:Oleaster,代碼行數:12,代碼來源:RoboOleaster.java

示例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;
}
 
開發者ID:bangarharshit,項目名稱:Oleaster,代碼行數:12,代碼來源:RoboOleaster.java

示例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();
    }
}
 
開發者ID:bangarharshit,項目名稱:Oleaster,代碼行數:11,代碼來源:RoboOleaster.java

示例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);
}
 
開發者ID:QACore,項目名稱:Java-Testing-Toolbox,代碼行數:16,代碼來源:ParallelParameterizedTest.java

示例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);
	}
}
 
開發者ID:vanilladb,項目名稱:vanillacore,代碼行數:18,代碼來源:IsolatedClassLoaderSuite.java

示例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
  }
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:14,代碼來源:FilterRegistry.java


注:本文中的org.junit.runners.ParentRunner類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。