本文整理了Java中org.junit.runner.Request
类的一些代码示例,展示了Request
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request
类的具体详情如下:
包路径:org.junit.runner.Request
类名称:Request
[英]A Request
is an abstract description of tests to be run. Older versions of JUnit did not need such a concept--tests to be run were described either by classes containing tests or a tree of org.junit.Tests. However, we want to support filtering and sorting, so we need a more abstract specification than the tests themselves and a richer specification than just the classes.
The flow when JUnit runs tests is that a Request
specifies some tests to be run -> a org.junit.runner.Runner is created for each class implied by the Request
-> the org.junit.runner.Runner returns a detailed org.junit.runner.Descriptionwhich is a tree structure of the tests to be run.
[中]Request
是对要运行的测试的抽象描述。较旧版本的JUnit不需要这样的概念——要运行的测试由包含测试的类或组织树描述。朱尼特。测验。然而,我们希望支持过滤和排序,因此我们需要一个比测试本身更抽象的规范,以及一个比类更丰富的规范。
JUnit运行测试时的流程是Request
指定要运行的一些测试->组织。朱尼特。跑步者为Request
->组织隐含的每个类创建Runner。朱尼特。跑步者Runner返回一个详细的组织。朱尼特。跑步者description是要运行的测试的树结构。
代码示例来源:origin: org.testng/testng
JUnitCore core = new JUnitCore();
core.addListener(new RL());
Request r = Request.aClass(testCase);
return core.run(r.filterWith(new Filter() {
代码示例来源:origin: junit-team/junit4
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();
}
代码示例来源:origin: junit-team/junit4
/**
* Run all the tests in <code>classes</code>.
*
* @param computer Helps construct Runners from classes
* @param classes the classes containing tests
* @return a {@link Result} describing the details of the test run and the failed tests.
*/
public Result run(Computer computer, Class<?>... classes) {
return run(Request.classes(computer, classes));
}
代码示例来源:origin: junit-team/junit4
public JUnit4TestAdapter(final Class<?> newTestClass, JUnit4TestAdapterCache cache) {
fCache = cache;
fNewTestClass = newTestClass;
fRunner = Request.classWithoutSuiteMethod(newTestClass).getRunner();
}
代码示例来源:origin: junit-team/junit4
/**
* Create a <code>Request</code> that, when processed, will run a single test.
* This is done by filtering out all other tests. This method is used to support rerunning
* single tests.
*
* @param clazz the class of the test
* @param methodName the name of the test
* @return a <code>Request</code> that will cause a single test be run
*/
public static Request method(Class<?> clazz, String methodName) {
Description method = Description.createTestDescription(clazz, methodName);
return Request.aClass(clazz).filterWith(method);
}
代码示例来源:origin: apache/geode
public static Result runTest(final Class<?> test) {
JUnitCore junitCore = new JUnitCore();
return junitCore.run(Request.aClass(test).getRunner());
}
代码示例来源:origin: SpoonLabs/nopol
private static void runTest(String test) {
try {
String[] classAndMethod = test.split("#");
System.out.println(test);
Request request = Request.method(Class.forName(classAndMethod[0]), classAndMethod[1]);
JUnitCore junit = new JUnitCore();
junit.addListener(new TextListener(System.out));
junit.run(request);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: authorjapps/zerocode
private Runnable createRunnable(Class<?> testClass, String testMathod) {
return () -> {
LOGGER.info(Thread.currentThread().getName() + " Parallel Junit test- *Start. Time = " + now());
Result result = (new JUnitCore()).run(Request.method(testClass, testMathod));
LOGGER.info(Thread.currentThread().getName() + " Parallel Junit test- * End. Time = " + now());
if (result.wasSuccessful()) {
passedCounter.incrementAndGet();
} else {
failedCounter.incrementAndGet();
}
};
}
代码示例来源:origin: com.novocode/junit-interface
RichLogger logger = new RichLogger(loggers, settings, testClassName);
EventDispatcher ed = new EventDispatcher(logger, eventHandler, settings, fingerprint);
JUnitCore ju = new JUnitCore();
ju.addListener(ed);
if (runListener != null) {
ju.addListener(createRunListener(runListener));
Class<?> cl = testClassLoader.loadClass(testClassName);
if(shouldRun(fingerprint, cl, settings)) {
Request request = Request.classes(cl);
if(globPatterns.size() > 0) request = new SilentFilterRequest(request, new GlobFilter(settings, globPatterns));
if(testFilter.length() > 0) request = new SilentFilterRequest(request, new TestFilter(testFilter, ed));
代码示例来源:origin: greghaskins/spectrum
private static Result runWithJUnit(final Runner runner) {
return new JUnitCore().run(Request.runner(runner));
}
}
代码示例来源:origin: junit-team/junit4
/**
* Run all the tests contained in <code>request</code>.
*
* This variant should be used if {@code core} has attached listeners that this
* run should notify.
*
* @param request the request describing tests
* @param core a JUnitCore to delegate to.
* @return a {@link Result} describing the details of the test run and the failed tests.
*/
public Result run(Request request, JUnitCore core) {
core.addListener(history.listener());
return core.run(sortRequest(request).getRunner());
}
代码示例来源:origin: google/j2objc
/**
* Run all the tests in <code>classes</code>.
*
* @param classes the classes containing tests
* @return a {@link Result} describing the details of the test run and the failed tests.
*/
public Result run(Class<?>... classes) {
return run(Request.classes(defaultComputer(), classes));
}
代码示例来源:origin: effektif/effektif
public static void run(Configuration configuration, Class<?> clazz, String methodName) {
try {
Request request = null;
if (clazz!=null && methodName!=null) {
request = Request.method(clazz, methodName);
} else {
Suite suite = new Suite(new JUnit4Builder(), API_TEST_CLASSES);
request = Request.runner(suite);
}
Configuration originalConfiguration = WorkflowTest.cachedConfiguration;
WorkflowTest.cachedConfiguration = configuration;
JUnitCore junitCore = new JUnitCore();
Result result = junitCore.run(request);
WorkflowTest.cachedConfiguration = originalConfiguration;
checkResult(result);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.robovm/robovm-junit-server
/**
* Run a single method test
*
* @param jUnitCore
* @param className
* @param method
*/
protected void runMethodOnly(JUnitCore jUnitCore, String className, String method) {
try {
jUnitCore.run(Request.method(Class.forName(className), method));
} catch (ClassNotFoundException e) {
error("Test class not found: " + className);
printStackTrace(e);
}
}
代码示例来源:origin: junit-team/junit4
/**
* Run all the tests contained in <code>request</code>.
*
* @param request the request describing tests
* @return a {@link Result} describing the details of the test run and the failed tests.
*/
public Result run(Request request) {
return run(request.getRunner());
}
代码示例来源:origin: junit-team/junit4
@Override
protected Runner createRunner() {
Runner runner = request.getRunner();
try {
ordering.apply(runner);
} catch (InvalidOrderingException e) {
return new ErrorReportingRunner(ordering.getClass(), e);
}
return runner;
}
}
代码示例来源:origin: junit-team/junit4
/**
* Returns a Request that only runs tests whose {@link Description}
* matches the given description.
*
* <p>Returns an empty {@code Request} if {@code desiredDescription} is not a single test and filters all but the single
* test if {@code desiredDescription} is a single test.</p>
*
* @param desiredDescription {@code Description} of those tests that should be run
* @return the filtered Request
*/
public Request filterWith(Description desiredDescription) {
return filterWith(Filter.matchMethodDescription(desiredDescription));
}
代码示例来源:origin: org.junit.vintage/junit-vintage-engine
private RunnerTestDescriptor determineRunnerTestDescriptor(Class<?> testClass, Runner runner,
List<RunnerTestDescriptorAwareFilter> filters, UniqueId engineId) {
RunnerTestDescriptor runnerTestDescriptor = createCompleteRunnerTestDescriptor(testClass, runner, engineId);
if (!filters.isEmpty()) {
if (runner instanceof Filterable) {
Filter filter = createOrFilter(filters, runnerTestDescriptor);
Runner filteredRunner = runnerTestDescriptor.toRequest().filterWith(filter).getRunner();
runnerTestDescriptor = createCompleteRunnerTestDescriptor(testClass, filteredRunner, engineId);
}
else {
Runner runnerToReport = (runner instanceof RunnerDecorator)
? ((RunnerDecorator) runner).getDecoratedRunner()
: runner;
logger.warn(() -> "Runner " + runnerToReport.getClass().getName() //
+ " (used on " + testClass.getName() + ") does not support filtering" //
+ " and will therefore be run completely.");
}
}
return runnerTestDescriptor;
}
代码示例来源:origin: com.github.dakusui/jcunit
private JUnit4Runner(Class clazz, String methodName, int startInclusive, int endExclusive) {
this.request = Request.classes(clazz).filterWith(
createFilter(methodName, startInclusive, endExclusive)
);
}
代码示例来源:origin: junit-team/junit4
/**
* Create a <code>Request</code> that, when processed, will run all the tests
* in a set of classes with the default <code>Computer</code>.
*
* @param classes the classes containing the tests
* @return a <code>Request</code> that will cause all tests in the classes to be run
*/
public static Request classes(Class<?>... classes) {
return classes(JUnitCore.defaultComputer(), classes);
}
内容来源于网络,如有侵权,请联系作者删除!