Search in sources :

Example 11 with Runner

use of org.junit.runner.Runner in project tests by datanucleus.

the class MultiConfigRunner method runnerForClass.

private Runner runnerForClass(Class<?> testClass) throws Exception {
    String config = System.getProperty("datanucleus.test.config", "default");
    Runner runner;
    if (TestCase.class.isAssignableFrom(testClass)) {
        runner = new JUnit38ConfigRunner(testClass, config);
    } else {
        runner = new JUnit4ConfigRunner(testClass, config);
    }
    return runner;
}
Also used : JUnit38ClassRunner(org.junit.internal.runners.JUnit38ClassRunner) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) Runner(org.junit.runner.Runner)

Example 12 with Runner

use of org.junit.runner.Runner in project kanonizo by kanonizo.

the class JUnit4TestRunner method runTest.

@Override
public KanonizoTestResult runTest(TestCase tc) {
    Request request = getRequest(tc);
    Runner testRunner = request.getRunner();
    Result testResult = runner.run(testRunner);
    List<KanonizoTestFailure> failures = testResult.getFailures().stream().map(failure -> new KanonizoTestFailure(failure.getException(), failure.getTrace())).collect(Collectors.toList());
    return new KanonizoTestResult(tc.getTestClass(), tc.getMethod(), testResult.wasSuccessful(), failures, testResult.getRunTime());
}
Also used : Arrays(java.util.Arrays) JUnitCore(org.junit.runner.JUnitCore) Result(org.junit.runner.Result) Request(org.junit.runner.Request) RunWith(org.junit.runner.RunWith) ArrayList(java.util.ArrayList) TestCase(org.kanonizo.framework.objects.TestCase) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) Runner(org.junit.runner.Runner) ClassRequest(org.junit.internal.requests.ClassRequest) KanonizoTestFailure(org.kanonizo.junit.KanonizoTestFailure) Method(java.lang.reflect.Method) Parameterized(org.junit.runners.Parameterized) KanonizoTestResult(org.kanonizo.junit.KanonizoTestResult) ParameterisedTestCase(org.kanonizo.framework.objects.ParameterisedTestCase) AssumptionViolatedException(org.junit.AssumptionViolatedException) BlockJUnit4ClassRunnerWithParameters(org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParameters) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Iterator(java.util.Iterator) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier) Filter(org.junit.runner.manipulation.Filter) Description(org.junit.runner.Description) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Ignore(org.junit.Ignore) RunNotifier(org.junit.runner.notification.RunNotifier) LogManager(org.apache.logging.log4j.LogManager) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) Runner(org.junit.runner.Runner) KanonizoTestFailure(org.kanonizo.junit.KanonizoTestFailure) Request(org.junit.runner.Request) ClassRequest(org.junit.internal.requests.ClassRequest) KanonizoTestResult(org.kanonizo.junit.KanonizoTestResult) Result(org.junit.runner.Result) KanonizoTestResult(org.kanonizo.junit.KanonizoTestResult)

Example 13 with Runner

use of org.junit.runner.Runner in project pinpoint by naver.

the class SharedPinpointPluginTest method execute.

private void execute(final TestInfo testInfo, final Properties properties) {
    try {
        final ClassLoader testClassLoader = createTestClassLoader(testInfo);
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                final Class<?> testClazz = loadClass();
                logger.debug("testClazz:{} cl:{}", testClazz.getName(), testClazz.getClassLoader());
                try {
                    MethodUtils.invokeSetMethod(testClazz, properties);
                } catch (Exception e) {
                    logger.warn(e, "invoker setter method failed. testClazz:{} testId:{}", testClazzName, testInfo.getTestId());
                }
                try {
                    JUnitCore junit = new JUnitCore();
                    junit.addListener(new PrintListener());
                    Runner runner = new ForkedPinpointPluginTestRunner(testClazz, testInfo.getTestId());
                    junit.run(runner);
                } catch (InitializationError error) {
                    logger.error(error, "test run fail testClazz:{} testId:{}", testClazzName, testInfo.getTestId());
                    List<Throwable> causes = error.getCauses();
                    for (Throwable cause : causes) {
                        logger.error(cause, "junit error Caused By:{}", cause.getMessage());
                    }
                }
            }

            private Class<?> loadClass() {
                try {
                    return testClassLoader.loadClass(testClazzName);
                } catch (ClassNotFoundException e) {
                    logger.error(e, "testClazz:{} not found", testClazzName, testInfo.getTestId());
                    throw new RuntimeException(e);
                }
            }
        };
        String threadName = testClazzName + " " + testInfo.getTestId() + " Thread";
        Thread testThread = newThread(runnable, threadName, testClassLoader);
        testThread.start();
        testThread.join(TimeUnit.MINUTES.toMillis(5));
        checkTerminatedState(testThread, testClazzName + " " + testInfo.getTestId());
    } catch (Exception e) {
        logger.error(e, "{}:{} execute failed:{}", testClazzName, testInfo.getTestId(), e.getMessage());
    } finally {
        ReflectPluginTestVerifier.getInstance().cleanUp(true);
    }
}
Also used : ForkedPinpointPluginTestRunner(com.navercorp.pinpoint.test.plugin.ForkedPinpointPluginTestRunner) Runner(org.junit.runner.Runner) JUnitCore(org.junit.runner.JUnitCore) InitializationError(org.junit.runners.model.InitializationError) ForkedPinpointPluginTestRunner(com.navercorp.pinpoint.test.plugin.ForkedPinpointPluginTestRunner) ChildFirstClassLoader(com.navercorp.pinpoint.test.plugin.util.ChildFirstClassLoader) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with Runner

use of org.junit.runner.Runner in project pinpoint by naver.

the class PinpointPluginTestSuite method sort.

public void sort(Sorter sorter) {
    synchronized (childrenLock) {
        for (Runner each : getFilteredChildren()) {
            sorter.apply(each);
        }
        List<Runner> sortedChildren = new ArrayList<>(getFilteredChildren());
        Collections.sort(sortedChildren, comparator(sorter));
        filteredChildren = Collections.unmodifiableCollection(sortedChildren);
    }
}
Also used : Runner(org.junit.runner.Runner) ArrayList(java.util.ArrayList)

Example 15 with Runner

use of org.junit.runner.Runner in project jena by apache.

the class AbstractRunnerOfTests method build.

/**
 * Do one level of tests. test are {@link Runnable Runnables} that each succeed or fail with an exception.
 */
public static RunnerOneManifest build(EarlReport report, Manifest manifest, Function<ManifestEntry, Runnable> maker, String prefix) {
    Description description = Description.createSuiteDescription(manifest.getName());
    if (PrintManifests)
        out.println(manifest.getFileName() + " :: " + manifest.getName());
    RunnerOneManifest thisLevel = new RunnerOneManifest(manifest, description);
    Iterator<String> sub = manifest.includedManifests();
    while (sub.hasNext()) {
        if (PrintManifests)
            out.incIndent();
        String mf = sub.next();
        Manifest manifestSub = Manifest.parse(mf);
        Runner runner = build(report, manifestSub, maker, prefix);
        thisLevel.add(runner);
        if (PrintManifests)
            out.decIndent();
    }
    // Check entries do have test targets.
    manifest.entries().forEach(entry -> {
        if (entry.getAction() == null)
            throw new RuntimeException("Missing: action [" + entry.getEntry() + "]");
        if (entry.getName() == null)
            throw new RuntimeException("Missing: label [" + entry.getEntry() + "]");
    });
    prepareTests(report, thisLevel, manifest, maker, prefix);
    return thisLevel;
}
Also used : Runner(org.junit.runner.Runner) ParentRunner(org.junit.runners.ParentRunner) Description(org.junit.runner.Description)

Aggregations

Runner (org.junit.runner.Runner)64 Test (org.junit.Test)21 Description (org.junit.runner.Description)14 ParentRunner (org.junit.runners.ParentRunner)13 ArrayList (java.util.ArrayList)12 JUnitCore (org.junit.runner.JUnitCore)11 Request (org.junit.runner.Request)11 RunNotifier (org.junit.runner.notification.RunNotifier)11 Filter (org.junit.runner.manipulation.Filter)10 NoTestsRemainException (org.junit.runner.manipulation.NoTestsRemainException)9 Result (org.junit.runner.Result)8 Method (java.lang.reflect.Method)7 Failure (org.junit.runner.notification.Failure)7 InitializationError (org.junit.runners.model.InitializationError)7 JUnit38ClassRunner (org.junit.internal.runners.JUnit38ClassRunner)5 RunnerSpy (org.junit.runner.RunnerSpy)5 LinkedList (java.util.LinkedList)4 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)4 File (java.io.File)3 ImmutableMap (com.google.common.collect.ImmutableMap)2