org.junit.runner.Runner#run()源码实例Demo

下面列出了org.junit.runner.Runner#run() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: 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());
}
 
源代码2 项目: spring-analysis-note   文件: 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 default JUnit 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);
	}

	// @formatter:off
	assertAll(
		() -> assertEquals(expectedStartedCount, listener.getTestStartedCount(), "tests started for [" + testClass + "]"),
		() -> assertEquals(expectedFailedCount, listener.getTestFailureCount(), "tests failed for [" + testClass + "]"),
		() -> assertEquals(expectedFinishedCount, listener.getTestFinishedCount(), "tests finished for [" + testClass + "]"),
		() -> assertEquals(expectedIgnoredCount, listener.getTestIgnoredCount(), "tests ignored for [" + testClass + "]"),
		() -> assertEquals(expectedAssumptionFailedCount, listener.getTestAssumptionFailureCount(), "failed assumptions for [" + testClass + "]")
	);
	// @formatter:on
}
 
源代码3 项目: java-technology-stack   文件: 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 default JUnit 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);
	}

	// @formatter:off
	assertAll(
		() -> assertEquals(expectedStartedCount, listener.getTestStartedCount(), "tests started for [" + testClass + "]"),
		() -> assertEquals(expectedFailedCount, listener.getTestFailureCount(), "tests failed for [" + testClass + "]"),
		() -> assertEquals(expectedFinishedCount, listener.getTestFinishedCount(), "tests finished for [" + testClass + "]"),
		() -> assertEquals(expectedIgnoredCount, listener.getTestIgnoredCount(), "tests ignored for [" + testClass + "]"),
		() -> assertEquals(expectedAssumptionFailedCount, listener.getTestAssumptionFailureCount(), "failed assumptions for [" + testClass + "]")
	);
	// @formatter:on
}
 
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);
}
 
源代码5 项目: pushfish-android   文件: JUnitTestClassExecuter.java
private void runTestClass(String testClassName) throws ClassNotFoundException {
    final Class<?> testClass = Class.forName(testClassName, false, applicationClassLoader);
    Request request = Request.aClass(testClass);
    if (options.hasCategoryConfiguration()) {
        Transformer<Class<?>, String> transformer = new Transformer<Class<?>, String>() {
            public Class<?> transform(final String original) {
                try {
                    return applicationClassLoader.loadClass(original);
                } catch (ClassNotFoundException e) {
                    throw new InvalidUserDataException(String.format("Can't load category class [%s].", original), e);
                }
            }
        };
        request = request.filterWith(new CategoryFilter(
                CollectionUtils.collect(options.getIncludeCategories(), transformer),
                CollectionUtils.collect(options.getExcludeCategories(), transformer)
        ));
    }

    if (!options.getIncludedTests().isEmpty()) {
        request = request.filterWith(new MethodNameFilter(options.getIncludedTests()));
    }

    Runner runner = request.getRunner();
    //In case of no matching methods junit will return a ErrorReportingRunner for org.junit.runner.manipulation.Filter.class.
    //Will be fixed with adding class filters
    if (!org.junit.runner.manipulation.Filter.class.getName().equals(runner.getDescription().getDisplayName())) {
        RunNotifier notifier = new RunNotifier();
        notifier.addListener(listener);
        runner.run(notifier);
    }
}
 
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);
}
 
源代码7 项目: pushfish-android   文件: JUnitTestClassExecuter.java
private void runTestClass(String testClassName) throws ClassNotFoundException {
    final Class<?> testClass = Class.forName(testClassName, true, applicationClassLoader);
    Request request = Request.aClass(testClass);
    if (options.hasCategoryConfiguration()) {
        Transformer<Class<?>, String> transformer = new Transformer<Class<?>, String>() {
            public Class<?> transform(final String original) {
                try {
                    return applicationClassLoader.loadClass(original);
                } catch (ClassNotFoundException e) {
                    throw new InvalidUserDataException(String.format("Can't load category class [%s].", original), e);
                }
            }
        };
        request = request.filterWith(new CategoryFilter(
                CollectionUtils.collect(options.getIncludeCategories(), transformer),
                CollectionUtils.collect(options.getExcludeCategories(), transformer)
        ));
    }

    if (!options.getIncludedTests().isEmpty()) {
        request = request.filterWith(new MethodNameFilter(options.getIncludedTests()));
    }

    Runner runner = request.getRunner();
    //In case of no matching methods junit will return a ErrorReportingRunner for org.junit.runner.manipulation.Filter.class.
    //Will be fixed with adding class filters
    if (!org.junit.runner.manipulation.Filter.class.getName().equals(runner.getDescription().getDisplayName())) {
        RunNotifier notifier = new RunNotifier();
        notifier.addListener(listener);
        runner.run(notifier);
    }
}
 
源代码8 项目: spoon-examples   文件: TestRunner.java
public static List<Failure> runTest(String fullQualifiedName, String testCaseName, String[] classpath) throws MalformedURLException, ClassNotFoundException {
    ClassLoader classLoader = new URLClassLoader(
            arrayStringToArrayUrl.apply(classpath),
            ClassLoader.getSystemClassLoader()
    );
    Request request = Request.method(classLoader.loadClass(fullQualifiedName), testCaseName);
    Runner runner = request.getRunner();
    RunNotifier fNotifier = new RunNotifier();
    final TestListener listener = new TestListener();
    fNotifier.addFirstListener(listener);
    fNotifier.fireTestRunStarted(runner.getDescription());
    runner.run(fNotifier);
    return listener.getTestFails();
}
 
源代码9 项目: spoon-examples   文件: TestRunner.java
public static List<Failure> runTest(String fullQualifiedName, String[] classpath) throws MalformedURLException, ClassNotFoundException {
    ClassLoader classLoader = new URLClassLoader(
            arrayStringToArrayUrl.apply(classpath),
            ClassLoader.getSystemClassLoader()
    );
    Request request = Request.classes(classLoader.loadClass(fullQualifiedName));
    Runner runner = request.getRunner();
    RunNotifier fNotifier = new RunNotifier();
    final TestListener listener = new TestListener();
    fNotifier.addFirstListener(listener);
    fNotifier.fireTestRunStarted(runner.getDescription());
    runner.run(fNotifier);
    return listener.getTestFails();
}
 
源代码10 项目: Pushjet-Android   文件: 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);
}
 
源代码11 项目: Pushjet-Android   文件: JUnitTestClassExecuter.java
private void runTestClass(String testClassName) throws ClassNotFoundException {
    final Class<?> testClass = Class.forName(testClassName, false, applicationClassLoader);
    Request request = Request.aClass(testClass);
    if (options.hasCategoryConfiguration()) {
        Transformer<Class<?>, String> transformer = new Transformer<Class<?>, String>() {
            public Class<?> transform(final String original) {
                try {
                    return applicationClassLoader.loadClass(original);
                } catch (ClassNotFoundException e) {
                    throw new InvalidUserDataException(String.format("Can't load category class [%s].", original), e);
                }
            }
        };
        request = request.filterWith(new CategoryFilter(
                CollectionUtils.collect(options.getIncludeCategories(), transformer),
                CollectionUtils.collect(options.getExcludeCategories(), transformer)
        ));
    }

    if (!options.getIncludedTests().isEmpty()) {
        request = request.filterWith(new MethodNameFilter(options.getIncludedTests()));
    }

    Runner runner = request.getRunner();
    //In case of no matching methods junit will return a ErrorReportingRunner for org.junit.runner.manipulation.Filter.class.
    //Will be fixed with adding class filters
    if (!org.junit.runner.manipulation.Filter.class.getName().equals(runner.getDescription().getDisplayName())) {
        RunNotifier notifier = new RunNotifier();
        notifier.addListener(listener);
        runner.run(notifier);
    }
}
 
源代码12 项目: Pushjet-Android   文件: 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);
}
 
源代码13 项目: Pushjet-Android   文件: JUnitTestClassExecuter.java
private void runTestClass(String testClassName) throws ClassNotFoundException {
    final Class<?> testClass = Class.forName(testClassName, true, applicationClassLoader);
    Request request = Request.aClass(testClass);
    if (options.hasCategoryConfiguration()) {
        Transformer<Class<?>, String> transformer = new Transformer<Class<?>, String>() {
            public Class<?> transform(final String original) {
                try {
                    return applicationClassLoader.loadClass(original);
                } catch (ClassNotFoundException e) {
                    throw new InvalidUserDataException(String.format("Can't load category class [%s].", original), e);
                }
            }
        };
        request = request.filterWith(new CategoryFilter(
                CollectionUtils.collect(options.getIncludeCategories(), transformer),
                CollectionUtils.collect(options.getExcludeCategories(), transformer)
        ));
    }

    if (!options.getIncludedTests().isEmpty()) {
        request = request.filterWith(new MethodNameFilter(options.getIncludedTests()));
    }

    Runner runner = request.getRunner();
    //In case of no matching methods junit will return a ErrorReportingRunner for org.junit.runner.manipulation.Filter.class.
    //Will be fixed with adding class filters
    if (!org.junit.runner.manipulation.Filter.class.getName().equals(runner.getDescription().getDisplayName())) {
        RunNotifier notifier = new RunNotifier();
        notifier.addListener(listener);
        runner.run(notifier);
    }
}
 
源代码14 项目: spectrum   文件: WhenRunningTheTests.java
@Before
public void before() throws Exception {
  final Runner runner = new Spectrum(Fixture.getSpecWithPassingAndFailingTests());
  this.runNotifier = mock(RunNotifier.class);

  runner.run(this.runNotifier);
}
 
源代码15 项目: elasticsearch-helper   文件: ListenerSuite.java
@Override
protected void runChild(Runner runner, RunNotifier notifier) {
    notifier.addListener(listener);
    runner.run(notifier);
    notifier.removeListener(listener);
}
 
源代码16 项目: xtext-eclipse   文件: AllScenariosRunner.java
@Override
protected void runChild(Runner child, RunNotifier notifier) {
	child.run(notifier);
}
 
源代码17 项目: metafacture-core   文件: MetamorphTestSuite.java
@Override
protected void runChild(final Runner child, final RunNotifier notifier) {
    child.run(notifier);
}
 
源代码18 项目: lambda-behave   文件: JunitSuiteRunner.java
@Override
protected void runChild(Runner child, RunNotifier notifier) {
	child.run(notifier);
}
 
源代码19 项目: selenium   文件: JavaScriptTestSuite.java
@Override
protected void runChild(Runner child, RunNotifier notifier) {
  child.run(notifier);
}
 
源代码20 项目: senbot   文件: ParameterizedCucumber.java
/**
 * Runs a child
 * 
 * @param child
 *            The child you want to run
 * @param notifier
 *            The notifier
 */
@Override
protected void runChild(Runner child, RunNotifier notifier) {
	child.run(notifier);
}
 
 方法所在类