Search in sources :

Example 26 with Runner

use of org.junit.runner.Runner in project junit4 by junit-team.

the class SingleMethodTest method parameterizedFilterToSingleMethod.

@Test
public void parameterizedFilterToSingleMethod() throws Exception {
    count = 0;
    Runner runner = Request.method(ParameterizedOneTimeSetup.class, "one[0]").getRunner();
    Result result = new JUnitCore().run(runner);
    assertEquals(1, result.getRunCount());
}
Also used : Runner(org.junit.runner.Runner) JUnitCore(org.junit.runner.JUnitCore) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 27 with Runner

use of org.junit.runner.Runner in project junit4 by junit-team.

the class SingleMethodTest method eliminateUnnecessaryTreeBranches.

@Test
public void eliminateUnnecessaryTreeBranches() throws Exception {
    Runner runner = Request.aClass(OneTwoSuite.class).filterWith(Description.createTestDescription(TestOne.class, "a")).getRunner();
    Description description = runner.getDescription();
    assertEquals(1, description.getChildren().size());
}
Also used : Runner(org.junit.runner.Runner) Description(org.junit.runner.Description) Test(org.junit.Test)

Example 28 with Runner

use of org.junit.runner.Runner in project junit4 by junit-team.

the class AnnotatedBuilderTest method memberClassDeepInsideAnnotatedMemberClass_isRunWithParentMemberClassRunner.

@Test
public void memberClassDeepInsideAnnotatedMemberClass_isRunWithParentMemberClassRunner() throws Exception {
    Runner runner = builder.runnerForClass(OuterClass.InnerClassWithOwnRunWith.MostInnerClass.class);
    assertThat(runner, is(instanceOf(InnerRunner.class)));
    RunnerSpy runnerSpy = (RunnerSpy) runner;
    assertThat(runnerSpy.getInvokedTestClass(), is((Object) OuterClass.InnerClassWithOwnRunWith.MostInnerClass.class));
}
Also used : Runner(org.junit.runner.Runner) RunnerSpy(org.junit.runner.RunnerSpy) Test(org.junit.Test)

Example 29 with Runner

use of org.junit.runner.Runner in project junit4 by junit-team.

the class AnnotatedBuilderTest method annotatedMemberClassInsideAnnotatedTopLevelClass_isRunWithOwnRunner.

@Test
public void annotatedMemberClassInsideAnnotatedTopLevelClass_isRunWithOwnRunner() throws Exception {
    Runner runner = builder.runnerForClass(OuterClass.InnerClassWithOwnRunWith.class);
    assertThat(runner, is(instanceOf(InnerRunner.class)));
    RunnerSpy runnerSpy = (RunnerSpy) runner;
    assertThat(runnerSpy.getInvokedTestClass(), is((Object) OuterClass.InnerClassWithOwnRunWith.class));
}
Also used : Runner(org.junit.runner.Runner) RunnerSpy(org.junit.runner.RunnerSpy) Test(org.junit.Test)

Example 30 with Runner

use of org.junit.runner.Runner in project gerrit by GerritCodeReview.

the class ConfigSuite method runnersFor.

private static List<Runner> runnersFor(Class<?> clazz) {
    Method defaultConfig = getDefaultConfig(clazz);
    List<Method> configs = getConfigs(clazz);
    Map<String, org.eclipse.jgit.lib.Config> configMap = callConfigMapMethod(getConfigMap(clazz), configs);
    Field parameterField = getOnlyField(clazz, Parameter.class);
    checkArgument(parameterField != null, "No @ConfigSuite.Parameter found");
    Field nameField = getOnlyField(clazz, Name.class);
    List<Runner> result = Lists.newArrayListWithCapacity(configs.size() + 1);
    try {
        result.add(new ConfigRunner(clazz, parameterField, nameField, null, callConfigMethod(defaultConfig)));
        for (Method m : configs) {
            result.add(new ConfigRunner(clazz, parameterField, nameField, m.getName(), callConfigMethod(m)));
        }
        for (Map.Entry<String, org.eclipse.jgit.lib.Config> e : configMap.entrySet()) {
            result.add(new ConfigRunner(clazz, parameterField, nameField, e.getKey(), e.getValue()));
        }
        return result;
    } catch (InitializationError e) {
        System.err.println("Errors initializing runners:");
        for (Throwable t : e.getCauses()) {
            t.printStackTrace();
        }
        throw new RuntimeException(e);
    }
}
Also used : BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) Runner(org.junit.runner.Runner) InitializationError(org.junit.runners.model.InitializationError) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Field(java.lang.reflect.Field) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

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