本文整理汇总了Java中org.junit.runner.Runner.run方法的典型用法代码示例。如果您正苦于以下问题:Java Runner.run方法的具体用法?Java Runner.run怎么用?Java Runner.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.junit.runner.Runner
的用法示例。
在下文中一共展示了Runner.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runTestsAndAssertCounters
import org.junit.runner.Runner; //导入方法依赖的package包/类
/**
* 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: runEnabledTests
import org.junit.runner.Runner; //导入方法依赖的package包/类
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);
}
示例3: runTest
import org.junit.runner.Runner; //导入方法依赖的package包/类
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();
}
示例4: runJUnitRequest
import org.junit.runner.Runner; //导入方法依赖的package包/类
public static Result runJUnitRequest(Request request) {
RunNotifier notifier = new RunNotifier();
Result result = new Result();
RunListener listener = result.createListener();
notifier.addListener(listener);
Runner runner = request.getRunner();
runner.run(notifier);
return result;
}
示例5: runTestClass
import org.junit.runner.Runner; //导入方法依赖的package包/类
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);
}
}
示例6: runTestClass
import org.junit.runner.Runner; //导入方法依赖的package包/类
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);
}
}
示例7: runAnnotatedTestClass
import org.junit.runner.Runner; //导入方法依赖的package包/类
private void runAnnotatedTestClass(Class<?> testClass, RunWith runWith)
throws Exception {
Class<? extends Runner> runnerClass = runWith.value();
Constructor<? extends Runner> constructor = runnerClass
.getConstructor(Class.class);
Runner runner = constructor.newInstance(testClass);
RunNotifier notifier = new RunNotifier();
notifier.addListener(new MyListener());
runner.run(notifier);
}
示例8: testSingleClass
import org.junit.runner.Runner; //导入方法依赖的package包/类
public static XSPResult testSingleClass(Class<?> testClass) {
ConsoleLogRecorder recorder = new ConsoleLogRecorder();
recorder.startRecording();
XSPResult xspResult = new XSPResult();
Request request = Request.aClass(testClass);
Result result = new Result();
RunNotifier runNotifier = buildRunNotifier(xspResult, result);
Runner testRunner = request.getRunner();
testRunner.run(runNotifier);
recorder.stopRecordingAndResetSystem();
xspResult.applyResult(result, recorder);
return xspResult;
}
示例9: testWithRequestFromClassAndSimpleResultObject
import org.junit.runner.Runner; //导入方法依赖的package包/类
@Test
public void testWithRequestFromClassAndSimpleResultObject() {
Request request = Request.aClass(TestMock.class);
Result result = new Result();
Runner testRunner = request.getRunner();
RunNotifier runNotifier = new RunNotifier();
runNotifier.addListener(result.createListener());
testRunner.run(runNotifier);
assertEquals(3, result.getRunCount());
assertEquals(2, result.getFailureCount());
assertEquals(1, result.getIgnoreCount());
}
示例10: runChild
import org.junit.runner.Runner; //导入方法依赖的package包/类
@Override
protected void runChild(Runner child, RunNotifier notifier) {
EchoingListener el = new EchoingListener((LogFileTestRunner)child);
try {
notifier.addListener(el);
child.run(notifier);
} finally {
notifier.removeListener(el);
}
}
示例11: run
import org.junit.runner.Runner; //导入方法依赖的package包/类
@Override
public void run(RunNotifier notifier) {
classRunner.run(notifier);
for (Runner childRunner : childRunners) {
childRunner.run(notifier);
}
}
示例12: runChild
import org.junit.runner.Runner; //导入方法依赖的package包/类
@Override
protected void runChild(final Runner runner, final RunNotifier notifier) {
runner.run(notifier);
}
示例13: runChild
import org.junit.runner.Runner; //导入方法依赖的package包/类
@Override
protected void runChild(Runner runner, final RunNotifier notifier) {
runner.run(notifier);
}
示例14: runChild
import org.junit.runner.Runner; //导入方法依赖的package包/类
protected void runChild(Runner runner, RunNotifier notifier) {
runner.run(notifier);
}
示例15: runChild
import org.junit.runner.Runner; //导入方法依赖的package包/类
@Override
protected void runChild(Runner runner, RunNotifier notifier) {
notifier.addListener(listener);
runner.run(notifier);
notifier.removeListener(listener);
}