當前位置: 首頁>>代碼示例>>Java>>正文


Java Runner.run方法代碼示例

本文整理匯總了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());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:44,代碼來源:JUnitTestingUtils.java

示例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);
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:33,代碼來源:AbstractMultiTestRunner.java

示例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();
}
 
開發者ID:SpoonLabs,項目名稱:spoon-examples,代碼行數:15,代碼來源:TestRunner.java

示例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;
}
 
開發者ID:piotrturski,項目名稱:zohhak,代碼行數:10,代碼來源:JUnitLauncher.java

示例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);
    }
}
 
開發者ID:Pushjet,項目名稱:Pushjet-Android,代碼行數:33,代碼來源:JUnitTestClassExecuter.java

示例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);
    }
}
 
開發者ID:Pushjet,項目名稱:Pushjet-Android,代碼行數:33,代碼來源:JUnitTestClassExecuter.java

示例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);
   }
 
開發者ID:lucaspouzac,項目名稱:contiperf,代碼行數:11,代碼來源:AbstractContiPerfTest.java

示例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;
}
 
開發者ID:OpenNTF,項目名稱:BuildAndTestPattern4Xpages,代碼行數:16,代碼來源:XSPTestRunner.java

示例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());
}
 
開發者ID:OpenNTF,項目名稱:BuildAndTestPattern4Xpages,代碼行數:13,代碼來源:JUnitAPITest.java

示例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);
	}
}
 
開發者ID:Tesora,項目名稱:tesora-dve-pub,代碼行數:11,代碼來源:LogFileSuiteRunner.java

示例11: run

import org.junit.runner.Runner; //導入方法依賴的package包/類
@Override
public void run(RunNotifier notifier) {
  classRunner.run(notifier);

  for (Runner childRunner : childRunners) {
    childRunner.run(notifier);
  }
}
 
開發者ID:joshng,項目名稱:papaya,代碼行數:9,代碼來源:Nested.java

示例12: runChild

import org.junit.runner.Runner; //導入方法依賴的package包/類
@Override
protected void runChild(final Runner runner, final RunNotifier notifier) {
	runner.run(notifier);
}
 
開發者ID:xtf-cz,項目名稱:xtf,代碼行數:5,代碼來源:XTFTestSuite.java

示例13: runChild

import org.junit.runner.Runner; //導入方法依賴的package包/類
@Override
protected void runChild(Runner runner, final RunNotifier notifier) {
    runner.run(notifier);
}
 
開發者ID:easymall,項目名稱:easy-test,代碼行數:5,代碼來源:EasySuite.java

示例14: runChild

import org.junit.runner.Runner; //導入方法依賴的package包/類
protected void runChild(Runner runner, RunNotifier notifier) {
    runner.run(notifier);
}
 
開發者ID:PeterWippermann,項目名稱:parameterized-suite,代碼行數:4,代碼來源:ParameterizedSuite.java

示例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);
}
 
開發者ID:jprante,項目名稱:elasticsearch-client-http,代碼行數:7,代碼來源:ListenerSuite.java


注:本文中的org.junit.runner.Runner.run方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。