Java 类org.junit.runner.Runner 实例源码

项目:Reer    文件:JUnitTestClassExecuter.java   
private boolean allTestsFiltered(Runner runner, List<Filter> filters) {
    LinkedList<Description> queue = new LinkedList<Description>();
    queue.add(runner.getDescription());
    while (!queue.isEmpty()) {
        Description description = queue.removeFirst();
        queue.addAll(description.getChildren());
        boolean run = true;
        for (Filter filter : filters) {
            if (!filter.shouldRun(description)) {
                run = false;
                break;
            }
        }
        if (run) {
            return false;
        }
    }
    return true;
}
项目:Reer    文件:AllExceptIgnoredTestRunnerBuilder.java   
@Override
public Runner runnerForClass(Class<?> testClass) throws Throwable {
    try {
        return new BlockJUnit4ClassRunner(testClass);
    } catch (Throwable t) {
        //failed to instantiate BlockJUnitRunner. try deprecated JUnitRunner (for JUnit < 4.5)
        try {
            Class<Runner> runnerClass = (Class<Runner>) Thread.currentThread().getContextClassLoader().loadClass("org.junit.internal.runners.JUnit4ClassRunner");
            final Constructor<Runner> constructor = runnerClass.getConstructor(Class.class);
            return constructor.newInstance(testClass);
        } catch (Throwable e) {
            LoggerFactory.getLogger(getClass()).warn("Unable to load JUnit4 runner to calculate Ignored test cases", e);
        }
    }
    return null;
}
项目: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;
}
项目:spockito    文件:Spockito.java   
private static List<Runner> createRunners(final Class<?> clazz) throws InitializationError {
    final ValueConverter defaultValueConverter = getDefaultValueConverter(clazz);
    final List<Runner> runners = new ArrayList<>();
    final Table classWideTable = classWideTableOrNull(clazz);
    if (classWideTable != null) {
        for (final TableRow row : classWideTable) {
            runners.add(new SingleRowMultiTestRunner(clazz, row, defaultValueConverter));
        }
    } else {
        for (final FrameworkMethod testMethod : new TestClass(clazz).getAnnotatedMethods(Test.class)) {
            final Spockito.UseValueConverter useValueConverter = testMethod.getAnnotation(Spockito.UseValueConverter.class);
            final ValueConverter methodValueConverter = Spockito.getValueConverter(useValueConverter, defaultValueConverter);
            runners.add(new SingleTestMultiRowRunner(clazz, testMethod, methodValueConverter));
        }
    }
    return runners;
}
项目:spring4-understanding    文件:JUnitTestingUtils.java   
/**
 * Run the tests in the supplied {@code testClass}, using the specified
 * {@link Runner}, and assert the expectations of the test execution.
 *
 * <p>If the specified {@code runnerClass} is {@code null}, the tests
 * will be run with the runner that the test class is configured with
 * (i.e., via {@link RunWith @RunWith}) or the default JUnit runner.
 *
 * @param runnerClass the explicit runner class to use or {@code null}
 * if the implicit runner should be used
 * @param testClass the test class to run with JUnit
 * @param expectedStartedCount the expected number of tests that started
 * @param expectedFailedCount the expected number of tests that failed
 * @param expectedFinishedCount the expected number of tests that finished
 * @param expectedIgnoredCount the expected number of tests that were ignored
 * @param expectedAssumptionFailedCount the expected number of tests that
 * resulted in a failed assumption
 */
public static void runTestsAndAssertCounters(Class<? extends Runner> runnerClass, Class<?> testClass,
        int expectedStartedCount, int expectedFailedCount, int expectedFinishedCount, int expectedIgnoredCount,
        int expectedAssumptionFailedCount) throws Exception {

    TrackingRunListener listener = new TrackingRunListener();

    if (runnerClass != null) {
        Constructor<?> constructor = runnerClass.getConstructor(Class.class);
        Runner runner = (Runner) BeanUtils.instantiateClass(constructor, testClass);
        RunNotifier notifier = new RunNotifier();
        notifier.addListener(listener);
        runner.run(notifier);
    }
    else {
        JUnitCore junit = new JUnitCore();
        junit.addListener(listener);
        junit.run(testClass);
    }

    assertEquals("tests started for [" + testClass + "]:", expectedStartedCount, listener.getTestStartedCount());
    assertEquals("tests failed for [" + testClass + "]:", expectedFailedCount, listener.getTestFailureCount());
    assertEquals("tests finished for [" + testClass + "]:", expectedFinishedCount, listener.getTestFinishedCount());
    assertEquals("tests ignored for [" + testClass + "]:", expectedIgnoredCount, listener.getTestIgnoredCount());
    assertEquals("failed assumptions for [" + testClass + "]:", expectedAssumptionFailedCount, listener.getTestAssumptionFailureCount());
}
项目:aws-encryption-sdk-java    文件:FastTestsOnlySuite.java   
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);
                    }
                }
            }
    );
}
项目:registry    文件:CustomParameterizedRunner.java   
private List<Runner> createRunnersForParameters(
        Iterable<Object> allParameters, String namePattern,
        ParametersRunnerFactory runnerFactory) throws Exception {
    try {
        List<TestWithParameters> tests = createTestsForParameters(
                allParameters, namePattern);
        List<Runner> runners = new ArrayList<Runner>();
        for (TestWithParameters test : tests) {
            runners.add(runnerFactory
                    .createRunnerForTestWithParameters(test));
        }
        return runners;
    } catch (ClassCastException e) {
        throw parametersMethodReturnedWrongType();
    }
}
项目:rtest    文件:RealRunnerProviderImpl.java   
@Override
public Runner getClientRunner(Class<?> testClass) {
    String  serverHost = System.getProperty(SupportedConfigurationProperties.Client.SERVER_HOST, "localhost");
    Integer serverPort = Integer.parseInt(System.getProperty(SupportedConfigurationProperties.Client.SERVER_PORT, "7890"));

    SocketSupplier clientSocketSupplier = new RetrySupportClientSocketSupplier(
            new ClientSocketSupplier(serverHost, serverPort),
            Long.parseLong(
                    System.getProperty(SupportedConfigurationProperties.Client.MAX_CONNECTION_WAIT_PERIOD,
                                       String.valueOf(RetrySupportClientSocketSupplier.DEFAULT_MAX_WAIT_PERIOD_MS))),
            new DefaultClock(),
            new DefaultThreadSleeper()
    );
    DefaultRemoteInvoker remoteInvoker = new DefaultRemoteInvoker(clientSocketSupplier);
    ClientSideInternalRemoteRunner runner = new ClientSideInternalRemoteRunner(testClass, remoteInvoker);
    runner.init();
    return runner;
}
项目:rtest    文件:ServerSideInternalRemoteRunner.java   
private Runner resolveRealRunner(Class<?> testClass){
    RealRunner realRunner = testClass.getAnnotation(RealRunner.class);
    if(realRunner == null) {
        // the real runner annotation is not specified - we'll just use Spock's default
        // Sputnik runner
        try {
            return new Sputnik(testClass);
        } catch (InitializationError initializationError) {
            LOG.warn("Failed to initialize a sputnik runner", initializationError);
            throw new RTestException(initializationError);
        }
    }
    else {
        try {
            return realRunner.value().getConstructor(testClass.getClass()).newInstance(testClass);
        } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            throw new RTestException("Failed to instantiate the real runner ", e);
        }
    }
}
项目:hybris-commerce-eclipse-plugin    文件:HybrisJUnitRequest.java   
@Override
public Runner getRunner()
{
    Runner runner = null;
    try
    {
        runner = new DynamicClasspathHybrisJUnit4ClassRunner(clazz);
    }
    catch (InitializationError initializationError)
    {
        initializationError.printStackTrace();
        throw new RuntimeException(initializationError);
    }

    return runner;
}
项目:intellij-ce-playground    文件:IdeaSuite.java   
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;
}
项目:aaf-junit    文件:ConcurrentDependsOnClasspathSuite.java   
private void runChildren(@SuppressWarnings("hiding") final RunNotifier notifier) {
    RunnerScheduler currentScheduler = scheduler;
    try {
        List<Runner> roots = graph.getRoots().stream().map(r -> nameToRunner.get(r)).collect(Collectors.toList());
        for (Runner each : roots) {
            currentScheduler.schedule(new Runnable() {
                @Override
                public void run() {
                    ConcurrentDependsOnClasspathSuite.this.runChild(each, notifier);
                }
            });
        }
    } finally {
        currentScheduler.finished();
    }
}
项目:sql-layer    文件:SelectedParameterizedRunner.java   
@Override
protected List<Runner> getChildren() {
    List<Runner> children = super.getChildren();

    if (override != null) {
        for (Iterator<Runner> iterator = children.iterator(); iterator.hasNext(); ) {
            Runner child = iterator.next();
            String fName = child.getDescription().getDisplayName();
            if (fName.startsWith("[") && fName.endsWith("]")) {
                fName = fName.substring(1, fName.length()-1);
            }
            if (overrideIsRegex && !paramNameMatchesRegex(fName, override)) {
                iterator.remove();
            }
            else if (!overrideIsRegex && !fName.equals(override)) {
                iterator.remove();
            }
        }
    }        
    return children;
}
项目:sql-layer    文件:NamedParameterizedRunnerTest.java   
/**
 * Confirms that each given name has a {@linkplain ReifiedParamRunner} associated with it, and returns the
 * name -> runner map
 * @param runner the parameterized runner
 * @param names the expected names
 * @return a map of names to reified runners
 */
private static Map<String,ReifiedParamRunner> testParameterizations(NamedParameterizedRunner runner, String... names)
{
    List<Runner> children = runner.getChildren();
    assertEquals("children.size()", names.length, children.size());

    Set<String> expectedNames = new HashSet<>(names.length, 1.0f);
    for (String name : names) {
        assertTrue("unexpected error, duplicate name: " + name, expectedNames.add(name));
    }

    Map<String,ReifiedParamRunner> foundRunners = new HashMap<>();
    for (Runner child : children)
    {
        ReifiedParamRunner reified = (ReifiedParamRunner)child;
        String paramToString = reified.paramToString();
        assertNull("duplicate name: " + paramToString, foundRunners.put(paramToString, reified));
    }

    for (String expected : expectedNames)
    {
        assertTrue("didn't find expected param: " + expected, foundRunners.containsKey(expected));
    }

    return foundRunners;
}
项目:msgcodec    文件:TestUpgradesSuite.java   
private static List<Runner> createRunners(Function<Schema, MsgCodec> codecFactory) throws InitializationError {
    List<Runner> runners = new ArrayList<>();

    Schema originalSchema = PairedTestProtocols.getOriginalSchema();
    Schema upgradedSchema = PairedTestProtocols.getUpgradedSchema();

    try {
        for (Map.Entry<String, PairedMessages> messageEntry : PairedTestProtocols.createMessages().entrySet()) {
            runners.add(new InboundTest(originalSchema, upgradedSchema, codecFactory, "InboundTest." + messageEntry.getKey(), 
                    messageEntry.getValue().originalMessage, messageEntry.getValue().upgradedMessage));
            runners.add(new OutboundTest(originalSchema, upgradedSchema, codecFactory,"OutboundTest." + messageEntry.getKey(), 
                    messageEntry.getValue().originalMessage, messageEntry.getValue().upgradedMessage));
            runners.add(new InboundGroupTest(originalSchema, upgradedSchema, codecFactory, "InboundGroupTest." + messageEntry.getKey(),
                    messageEntry.getValue().originalMessage, messageEntry.getValue().upgradedMessage));
            runners.add(new OutboundGroupTest(originalSchema, upgradedSchema, codecFactory,"OutboundGroupTest." + messageEntry.getKey(),
                    messageEntry.getValue().originalMessage, messageEntry.getValue().upgradedMessage));
        }
    } catch (IncompatibleSchemaException e) {
        throw new InitializationError(e);
    }

    return runners;
}
项目:che    文件:TestRunnerUtil.java   
private static List<JUnit4TestReference> getRequestForClasses(String[] args) {
  List<JUnit4TestReference> suites = new LinkedList<>();
  for (String classFqn : args) {
    try {
      Class<?> aClass = Class.forName(classFqn);
      Request request = Request.aClass(aClass);
      Runner runner = request.getRunner();
      suites.add(new JUnit4TestReference(runner, runner.getDescription()));
    } catch (ClassNotFoundException ignored) {
    }
  }
  if (suites.isEmpty()) {
    System.err.print("No test found to run.");
    return emptyList();
  }
  return suites;
}
项目:eHMP    文件:ImporterIntegrationTestRunner.java   
public ImporterIntegrationTestRunner(Class<?> testClass, String connectionUri, int timeout, String dfn, PatientDemographics pt) throws Throwable {
    super(testClass, Collections.<Runner>emptyList());
    this.connectionUri = connectionUri;
    this.ptDfn = dfn;
    this.pt = pt;
    extractConfig = getExtractConfig(testClass);

    if (VistaSessionManager.getRpcTemplate() == null) {
        VistaSessionManager.startSession(timeout);
        ownsSession = true;
    }

    List<VistaDataChunk> chunks = fetchChunks();
    for (int i = 0; i < chunks.size(); i++)
        runners.add(new VistaDataChunkTestRunner(getTestClass().getJavaClass(), Collections.unmodifiableList(chunks), i));

}
项目:statechum    文件:ParameterizedSuite.java   
protected static List<Runner> renameRunners(List<Runner> runners, final String description)
{
    ArrayList<Runner> outcome = new ArrayList<Runner>(runners.size());
    for(final Runner r:runners)
        outcome.add(new Runner(){

            @Override
            public Description getDescription() {
                Description origDescr = r.getDescription();
                Description modifiedDescription=Description.createSuiteDescription("("+origDescr.getClassName()+")"+description, origDescr.getAnnotations().toArray(new Annotation[0]));
                for(Description child:origDescr.getChildren())
                    modifiedDescription.addChild(child);
                return modifiedDescription;
            }

            @Override
            public void run(RunNotifier notifier) {
                r.run(notifier);
            }});
    return outcome;
}
项目:play1-maven-plugin    文件:PlayJUnit4Provider.java   
private static void execute( Class<?> testClass, Notifier notifier, Filter filter )
    throws TestSetFailedException
{
    final int classModifiers = testClass.getModifiers();
    if ( !isAbstract( classModifiers ) && !isInterface( classModifiers ) )
    {
        Request request = aClass( testClass );
        if ( filter != null )
        {
            request = request.filterWith( filter );
        }
        Runner runner = request.getRunner();
        if ( countTestsInRunner( runner.getDescription() ) != 0 )
        {
            executeInPlayContext( runner, notifier );
        }
    }
}
项目:play1-maven-plugin    文件:PlayJUnit4Provider.java   
private void executeFailedMethod( RunNotifier notifier, Set<ClassMethod> failedMethods )
    throws TestSetFailedException
{
    for ( ClassMethod failedMethod : failedMethods )
    {
        try
        {
            Class<?> methodClass = Class.forName( failedMethod.getClazz(), true, testClassLoader );
            String methodName = failedMethod.getMethod();
            Runner runner = method( methodClass, methodName ).getRunner();
            executeInPlayContext( runner, notifier );
        }
        catch ( ClassNotFoundException e )
        {
            throw new TestSetFailedException( "Unable to create test class '" + failedMethod.getClazz() + "'", e );
        }
    }
}
项目:rest-cucumber    文件:RestExampleRunner.java   
private static List<Runner> buildRunners(RestRuntime runtime,
   CucumberExamples cucumberExamples, RestJUnitReporter jUnitReporter,
   CucumberFeature cucumberFeature) {
   List<Runner> runners = new ArrayList<Runner>();
   List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios();
   for (CucumberScenario scenario : exampleScenarios) {
      try {
         ExecutionUnitRunner exampleScenarioRunner =
            new RestExecutionUnitRunner(runtime, scenario, jUnitReporter,
               cucumberFeature);
         runners.add(exampleScenarioRunner);
      } catch (InitializationError e) {
         throw new CucumberInitException(e);
      }
   }
   return runners;
}
项目:lcm    文件:AllDefaultPossibilitiesBuilder.java   
@Override
public Runner runnerForClass(Class<?> testClass) throws Throwable {
    List<RunnerBuilder> builders = Arrays.asList(
            ignoredBuilder(),
            annotatedBuilder(),
            suiteMethodBuilder(),
            junit3Builder(),
            junit4Builder());

    for (RunnerBuilder each : builders) {
        Runner runner = each.safeRunnerForClass(testClass);
        if (runner != null) {
            return runner;
        }
    }
    return null;
}
项目:sosiefier    文件:ParallelComputer.java   
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;
}
项目:lcm    文件:AnnotatedBuilder.java   
public Runner buildRunner(Class<? extends Runner> runnerClass,
        Class<?> testClass) throws Exception {
    try {
        return runnerClass.getConstructor(Class.class).newInstance(
                new Object[]{testClass});
    } catch (NoSuchMethodException e) {
        try {
            return runnerClass.getConstructor(Class.class,
                    RunnerBuilder.class).newInstance(
                    new Object[]{testClass, fSuiteBuilder});
        } catch (NoSuchMethodException e2) {
            String simpleName = runnerClass.getSimpleName();
            throw new InitializationError(String.format(
                    CONSTRUCTOR_ERROR_FORMAT, simpleName, simpleName));
        }
    }
}
项目:tools-idea    文件:IdeaSuite.java   
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;
}
项目:tools-idea    文件:JUnit46ClassesRequestBuilder.java   
public static Request getClassesRequest(final String suiteName, Class[] classes, Map classMethods) {
  boolean canUseSuiteMethod = canUseSuiteMethod(classMethods);
  try {
    final Runner suite;
    if (canUseSuiteMethod) {
      suite = new IdeaSuite(collectWrappedRunners(classes), suiteName);
    } else {
      final AllDefaultPossibilitiesBuilder builder = new AllDefaultPossibilitiesBuilder(canUseSuiteMethod);
      suite = new IdeaSuite(builder, classes, suiteName);
    }
    return Request.runner(suite);
  }
  catch (InitializationError e) {
    throw new RuntimeException(e);
  }
}
项目:buck-cutom    文件:DelegateRunNotifier.java   
DelegateRunNotifier(Runner runner, RunNotifier delegate, long defaultTestTimeoutMillis) {
  this.runner = runner;
  this.delegate = delegate;
  this.finishedTests = new HashSet<Description>();
  this.defaultTestTimeoutMillis = defaultTestTimeoutMillis;
  this.timer = new Timer();
  this.hasTestThatExceededTimeout = new AtomicBoolean(false);

  // Because our fireTestRunFinished() does not seem to get invoked, we listen for the
  // delegate to fire a testRunFinished event so we can dispose of the timer.
  delegate.addListener(new RunListener() {
    @Override
    public void testRunFinished(Result result) throws Exception {
      onTestRunFinished();
    }
  });
}
项目:burst    文件:BurstJUnit4.java   
static List<Runner> explode(Class<?> cls) throws InitializationError {
  checkNotNull(cls, "cls");

  TestClass testClass = new TestClass(cls);
  List<FrameworkMethod> testMethods = testClass.getAnnotatedMethods(Test.class);

  List<FrameworkMethod> burstMethods = new ArrayList<>(testMethods.size());
  for (FrameworkMethod testMethod : testMethods) {
    Method method = testMethod.getMethod();
    for (Enum<?>[] methodArgs : Burst.explodeArguments(method)) {
      burstMethods.add(new BurstMethod(method, methodArgs));
    }
  }

  TestConstructor constructor = BurstableConstructor.findSingle(cls);
  Enum<?>[][] constructorArgsList = Burst.explodeArguments(constructor);
  List<Runner> burstRunners = new ArrayList<>(constructorArgsList.length);
  for (Enum<?>[] constructorArgs : constructorArgsList) {
    burstRunners.add(new BurstRunner(cls, constructor, constructorArgs, burstMethods));
  }

  return unmodifiableList(burstRunners);
}
项目:contiperf    文件:ContiPerfSuiteRunner.java   
@Override
public Runner runnerForClass(Class<?> testClass) throws Throwable {
    List<RunnerBuilder> builders = Arrays.asList(ignoredBuilder(),
        annotatedBuilder(), suiteMethodBuilder(), junit3Builder(),
        contiPerfSuiteBuilder() // extends and replaces the JUnit4
                    // builder
        );

    for (RunnerBuilder each : builders) {
    Runner runner = each.safeRunnerForClass(testClass);
    if (runner != null) {
        return runner;
    }
    }
    return null;
}
项目:lcm    文件:MaxCore.java   
private Request constructLeafRequest(List<Description> leaves) {
    final List<Runner> runners = new ArrayList<Runner>();
    for (Description each : leaves) {
        runners.add(buildRunner(each));
    }
    return new Request() {
        @Override
        public Runner getRunner() {
            try {
                return new Suite((Class<?>) null, runners) {
                };
            } catch (InitializationError e) {
                return new ErrorReportingRunner(null, e);
            }
        }
    };
}
项目:lcm    文件:MaxCore.java   
private Runner buildRunner(Description each) {
    if (each.toString().equals("TestSuite with 0 tests")) {
        return Suite.emptySuite();
    }
    if (each.toString().startsWith(MALFORMED_JUNIT_3_TEST_CLASS_PREFIX)) {
        // This is cheating, because it runs the whole class
        // to get the warning for this method, but we can't do better,
        // because JUnit 3.8's
        // thrown away which method the warning is for.
        return new JUnit38ClassRunner(new TestSuite(getMalformedTestClass(each)));
    }
    Class<?> type = each.getTestClass();
    if (type == null) {
        throw new RuntimeException("Can't build a runner from description [" + each + "]");
    }
    String methodName = each.getMethodName();
    if (methodName == null) {
        return Request.aClass(type).getRunner();
    }
    return Request.method(type, methodName).getRunner();
}
项目:emfstore-rest    文件:FuzzyRunner.java   
/**
 * Default constructor, called by JUnit.
 * 
 * @param clazz
 *            The root class of the suite.
 * @throws InitializationError
 *             If there
 */
public FuzzyRunner(Class<?> clazz) throws InitializationError {
    super(clazz, Collections.<Runner> emptyList());
    dataProvider = getDataProvider();
    dataProvider.setTestClass(getTestClass());
    dataProvider.init();
    FrameworkField dataField = getDataField();
    FrameworkField utilField = getUtilField();
    FrameworkField optionsField = getOptionsField();
    org.eclipse.emf.emfstore.fuzzy.Util util = dataProvider.getUtil();
    for (int i = 0; i < dataProvider.size(); i++) {
        FuzzyTestClassRunner runner = new FuzzyTestClassRunner(clazz,
            dataProvider, dataField, utilField, optionsField, util,
            i + 1);
        if (runner.getChildren().size() > 0) {
            runners.add(runner);
        }
    }
}
项目:emfstore-rest    文件:FilteredSuite.java   
@Override
protected List<Runner> getChildren() {
    boolean fsParameter = false;
    for (Annotation annotation : getTestClass().getAnnotations()) {
        if (annotation instanceof FilteredSuiteParameter) {
            for (String par : ((FilteredSuiteParameter) annotation).value()) {
                if (Boolean.parseBoolean(System.getProperty(par))) {
                    return super.getChildren();
                }
            }
            fsParameter = true;
        }
    }

    if (fsParameter) {
        return new ArrayList<Runner>();
    } else {
        return super.getChildren();
    }
}
项目:lcm    文件:ParallelComputer.java   
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;
}
项目:pitest    文件:RunnerSuiteFinder.java   
@Override
public List<Class<?>> apply(final Class<?> a) {
  try {
    final Runner runner = AdaptedJUnitTestUnit.createRunner(a);

    final List<Description> allChildren = new ArrayList<>();
    flattenChildren(allChildren, runner.getDescription());

    final Set<Class<?>> classes = new LinkedHashSet<>(
        runner.getDescription().getChildren().size());

    final List<Description> suites = FCollection.filter(allChildren,
        Prelude.or(isSuiteMethodRunner(runner), isSuite()));
    FCollection.flatMapTo(suites, descriptionToTestClass(), classes);

    classes.remove(a);
    return new ArrayList<>(classes);
  } catch (RuntimeException ex) {
    // some runners (looking at you spock) can throw a runtime exception
    // when the getDescription method is called.
    return Collections.emptyList();
  }

}
项目:pitest    文件:AdaptedJUnitTestUnit.java   
private void filterIfRequired(final ResultCollector rc, final Runner runner) {
  if (this.filter.hasSome()) {
    if (!(runner instanceof Filterable)) {
      LOG.warning("Not able to filter " + runner.getDescription()
          + ". Mutation may have prevented JUnit from constructing test");
      return;
    }
    final Filterable f = (Filterable) runner;
    try {
      f.filter(this.filter.value());
    } catch (final NoTestsRemainException e1) {
      rc.notifySkipped(this.getDescription());
      return;
    }
  }
}
项目:pitest    文件:JUnitCustomRunnerTestUnitFinder.java   
@Override
public List<TestUnit> findTestUnits(final Class<?> clazz) {

  final Runner runner = AdaptedJUnitTestUnit.createRunner(clazz);

  if (isExcluded(runner) || isNotARunnableTest(runner, clazz.getName()) || !isIncluded(clazz)) {
    return Collections.emptyList();
  }

  if (Filterable.class.isAssignableFrom(runner.getClass())
      && !shouldTreatAsOneUnit(clazz, runner)) {
    List<TestUnit> filteredUnits = splitIntoFilteredUnits(runner.getDescription());
    return filterUnitsByMethod(filteredUnits);
  } else {
    return Collections.<TestUnit> singletonList(new AdaptedJUnitTestUnit(
        clazz, Option.<Filter> none()));
  }
}
项目:pitest    文件:ParameterisedJUnitTestFinder.java   
@Override
public List<TestUnit> findTestUnits(final Class<?> clazz) {

  final Runner runner = AdaptedJUnitTestUnit.createRunner(clazz);
  if ((runner == null)
      || runner.getClass().isAssignableFrom(ErrorReportingRunner.class)) {
    return Collections.emptyList();
  }

  if (isParameterizedTest(runner)) {
    return handleParameterizedTest(clazz, runner.getDescription());
  }

  return Collections.emptyList();

}
项目:Reer    文件:AbstractMultiTestRunner.java   
private void initExecutions() {
    if (!executionsInitialized) {
        try {
            Runner descriptionProvider = createRunnerFor(Arrays.asList(target), Collections.<Filter>emptyList());
            templateDescription = descriptionProvider.getDescription();
        } catch (InitializationError initializationError) {
            throw UncheckedException.throwAsUncheckedException(initializationError);
        }
        createExecutions();
        for (Execution execution : executions) {
            execution.init(target, templateDescription);
        }
        executionsInitialized = true;
    }
}
项目:Reer    文件:AbstractMultiTestRunner.java   
private void runEnabledTests(RunNotifier nested) {
    if (enabledTests.isEmpty()) {
        return;
    }

    Runner runner;
    try {
        runner = createExecutionRunner();
    } catch (Throwable t) {
        runner = new CannotExecuteRunner(getDisplayName(), target, t);
    }

    try {
        if (!disabledTests.isEmpty()) {
            ((Filterable) runner).filter(new Filter() {
                @Override
                public boolean shouldRun(Description description) {
                    return !disabledTests.contains(description);
                }

                @Override
                public String describe() {
                    return "disabled tests";
                }
            });
        }
    } catch (NoTestsRemainException e) {
        return;
    }

    runner.run(nested);
}