当前位置: 首页>>代码示例>>Java>>正文


Java JUnitCore.run方法代码示例

本文整理汇总了Java中org.junit.runner.JUnitCore.run方法的典型用法代码示例。如果您正苦于以下问题:Java JUnitCore.run方法的具体用法?Java JUnitCore.run怎么用?Java JUnitCore.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.junit.runner.JUnitCore的用法示例。


在下文中一共展示了JUnitCore.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runTestsAndAssertCounters

import org.junit.runner.JUnitCore; //导入方法依赖的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: runTestAndVerifyHierarchies

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
private void runTestAndVerifyHierarchies(Class<? extends FooTestCase> testClass, boolean isFooContextActive,
		boolean isBarContextActive, boolean isBazContextActive) {

	JUnitCore jUnitCore = new JUnitCore();
	Result result = jUnitCore.run(testClass);
	assertTrue("all tests passed", result.wasSuccessful());

	assertThat(ContextHierarchyDirtiesContextTests.context, notNullValue());

	ConfigurableApplicationContext bazContext = (ConfigurableApplicationContext) ContextHierarchyDirtiesContextTests.context;
	assertEquals("baz", ContextHierarchyDirtiesContextTests.baz);
	assertThat("bazContext#isActive()", bazContext.isActive(), is(isBazContextActive));

	ConfigurableApplicationContext barContext = (ConfigurableApplicationContext) bazContext.getParent();
	assertThat(barContext, notNullValue());
	assertEquals("bar", ContextHierarchyDirtiesContextTests.bar);
	assertThat("barContext#isActive()", barContext.isActive(), is(isBarContextActive));

	ConfigurableApplicationContext fooContext = (ConfigurableApplicationContext) barContext.getParent();
	assertThat(fooContext, notNullValue());
	assertEquals("foo", ContextHierarchyDirtiesContextTests.foo);
	assertThat("fooContext#isActive()", fooContext.isActive(), is(isFooContextActive));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:ContextHierarchyDirtiesContextTests.java

示例3: runTaskCase

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Override
public void runTaskCase() throws Exception {
    AbstractCaseData.setCaseData(null);
    String caseDataInfo = this.tcr.getTaskCase().getCaseDataInfo();
    if (!caseDataInfo.isEmpty()) {
        CaseData caseData = AbstractCaseData.getCaseData(caseDataInfo);
        LOG.debug("Injecting case data: {} = {}", caseDataInfo, caseData.getValue());
        AbstractCaseData.setCaseData(caseData);
    }

    TaskCase tc = this.tcr.getTaskCase();
    LOG.debug("Loading case {}", tc.format());
    CaseRunListener trl = new CaseRunListener(this.db, this.tcr);
    JUnitCore core = new JUnitCore();
    core.addListener(trl);
    core.run(Request.method(Class.forName(tc.getCaseClass()), tc.getCaseMethod()));
}
 
开发者ID:tascape,项目名称:reactor,代码行数:18,代码来源:CaseRunnerJUnit4.java

示例4: run

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Test
public void run() {
	JUnitCore junitCore = new JUnitCore();
	Result result = junitCore.run(TestDummy.class);
	List<Failure>failures = result.getFailures();
	if(!(failures == null || failures.isEmpty())) {
		for(Failure f : failures) {
			System.out.println(f.getMessage());
		}
	}
	Assert.assertEquals(2, result.getRunCount());
	Assert.assertEquals(0, result.getIgnoreCount());
	Assert.assertEquals(0, result.getFailureCount());
	Assert.assertEquals("After was not executed", "true", System.getProperty("JUnit_After"));
	Assert.assertEquals("AfterClass was not executed", "true", System.getProperty("JUnit_AfterClass"));
}
 
开发者ID:david-888,项目名称:aspectj-junit-runner,代码行数:17,代码来源:JUnitLifeCycleTest.java

示例5: runTests

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
private static void runTests(){
	JUnitCore junit = new JUnitCore();
	Result result = junit.run(Tests.class);
	System.err.println("Ran " + result.getRunCount() + " tests in "+ result.getRunTime() +"ms.");
	if (result.wasSuccessful()) System.out.println("All tests were successfull!");
	else {
		System.err.println(result.getFailureCount() + "Failures:");
		for (Failure fail: result.getFailures()){
			System.err.println("Failure in: "+ fail.getTestHeader());
			System.err.println(fail.getMessage());
			System.err.println(fail.getTrace());
			System.err.println();
		}
	}
	
}
 
开发者ID:JULIELab,项目名称:JEmAS,代码行数:17,代码来源:EmotionAnalyzer_UI.java

示例6: runTests

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
public void runTests(String outputDir) {
    JUnitCore junit = new JUnitCore();
    if (outputDir == null) {
        junit.addListener(new TextListener(System.out));
    } else {
        junit.addListener(new JUnitResultFormatterAsRunListener(new XMLJUnitResultFormatter()) {
            @Override
            public void testStarted(Description description) throws Exception {
                formatter.setOutput(new FileOutputStream(
                        new File(outputDir, "TEST-" + description.getDisplayName() + ".xml")));
                super.testStarted(description);
            }
        });
    }
    junit.run(TestContainer.class);
}
 
开发者ID:cmu-db,项目名称:peloton-test,代码行数:17,代码来源:JUnitRunner.java

示例7: main

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
public static void main(String []argv)
{
	JUnitCore junit = new JUnitCore();
	Result result = null;
	do
	{
		result = junit.run(Request.method(PropertyIndexingTests.class, "derivedPropertyIndexing"));
	} while (result.getFailureCount() == 0 && false);
	System.out.println("Failures " + result.getFailureCount());
	if (result.getFailureCount() > 0)
	{
		for (Failure failure : result.getFailures())
		{
			failure.getException().printStackTrace();
		}
	}
	System.exit(0);
}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:19,代码来源:PropertyIndexingTests.java

示例8: main

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
  preFlightTest(args);
  table = args[0];
  family = args[1];
  TestIntegration.args = args;
  LOG.info("Starting integration tests");
  final JUnitCore junit = new JUnitCore();
  final JunitListener listener = new JunitListener();
  junit.addListener(listener);
  final String singleTest = System.getenv("TEST_NAME");
  final Request req;
  if (singleTest != null) {
    req = Request.method(TestIntegration.class, singleTest);
  } else {
    req = Request.aClass(TestIntegration.class);
  }
  final Result result = junit.run(req);
  LOG.info("Ran " + result.getRunCount() + " tests in "
           + result.getRunTime() + "ms");
  if (!result.wasSuccessful()) {
    LOG.error(result.getFailureCount() + " tests failed: "
              + result.getFailures());
    System.exit(1);
  }
  LOG.info("All tests passed!");
}
 
开发者ID:OpenTSDB,项目名称:asyncbigtable,代码行数:27,代码来源:TestIntegration.java

示例9: testTranslationFromJUnitRunner

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Test
public void testTranslationFromJUnitRunner() {
	JUnitCore core = new JUnitCore();

	Class<?> fooTestClass = new FooTestClassLoader().loadFooTestClass();
	Result result = core.run(fooTestClass);
	JUnitResultBuilder builder = new JUnitResultBuilder();
	JUnitResult junitResult = builder.build(result);

	assertFalse(junitResult.wasSuccessful());
	assertEquals(1, junitResult.getFailureCount());
	assertEquals(1, junitResult.getFailures().size());

	JUnitFailure junitFailure = junitResult.getFailures().get(0);
	assertTrue(junitFailure.isAssertionError());
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:17,代码来源:JUnitResultBuilderTest.java

示例10: getExecutableTest

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Override
	public Callable<AnalysisResults> getExecutableTest(final Class<?> test) {
		final JUnitCore core = this.testCore;
		return new Callable<AnalysisResults>() {
			
			@Override
			public AnalysisResults call() {
				try {
					//System.out.println("Starting "+test);
					Result result = core.run(test);
					AnalysisResults results = new AnalysisResults();
					
					results.put(JUNIT_TEST_RESULT, result);
					results.put(TEST_CLASS_NAME, test.getName());
					return results;
//					this.printTestRunSummary(); // TODO Move to AbstractRuntimeAnalyzer.runTests.
					
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
				
			}
		};
	}
 
开发者ID:spideruci,项目名称:tacoco,代码行数:26,代码来源:JUnitRunner.java

示例11: deploy

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Override
protected void deploy(final String... args) throws Exception {

    configure(args);
    final JUnitCore core = new JUnitCore();
    final Result result = core.run(test_classes.toArray(new Class[test_classes.size()]));
    for (Failure failure : failures) {
        result.getFailures().add(failure);
    }

    setProperty(TEST_RESULT, serializeAsBase64(result));
}
 
开发者ID:stacs-srg,项目名称:shabdiz,代码行数:13,代码来源:JUnitBootstrapCore.java

示例12: startBenchmark

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
public static void startBenchmark(Class<?> class1) {
	System.out.println("/************* Benchmark Started *************/");
	for (int i = 0; i < inputSizes.length; i++) {

		JUnitCore junit = new JUnitCore();
		size = inputSizes[i];
		System.out.println("Running for input size: "+size);
		junit.run(class1);
		System.out.println("Completed for input size : "+size);

	}	
	System.out.println("/*************  Benchmark End   **************/");


}
 
开发者ID:adnanmitf09,项目名称:Rubus,代码行数:16,代码来源:RubusBenchmark.java

示例13: main

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
public static void main(String[] argv) {
    JUnitCore junit = new JUnitCore();
    Result result = null;
    result = junit.run(Request.method(TestParser.class, "malformedTest4"));
    if (result.getFailureCount() > 0) {
        for (Failure failure : result.getFailures()) {
            failure.getException().printStackTrace();
        }
    }
    System.exit(0);

}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:13,代码来源:TestParser.java

示例14: doWork

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Override
protected int doWork() throws Exception {
  //this is called from the command line, so we should set to use the distributed cluster
  IntegrationTestingUtility.setUseDistributedCluster(conf);
  Class<?>[] classes = findIntegrationTestClasses();
  LOG.info("Found " + classes.length + " integration tests to run:");
  for (Class<?> aClass : classes) {
    LOG.info("  " + aClass);
  }
  JUnitCore junit = new JUnitCore();
  junit.addListener(new TextListener(System.out));
  Result result = junit.run(classes);

  return result.wasSuccessful() ? 0 : 1;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:16,代码来源:IntegrationTestsDriver.java

示例15: runTest

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
public synchronized void runTest(IContext context, UnitTest unitTest) throws ClassNotFoundException, CoreException
{
	TestSuite testSuite = unitTest.getUnitTest_TestSuite();
	
	/**
	 * Is Mf
	 */
	if (unitTest.getIsMf()) {
		try {
			runMfSetup(testSuite);
			runMicroflowTest(unitTest.getName(), unitTest);
		}
		finally {
			runMfTearDown(testSuite);
		}
	}

	/**
	 * Is java
	 */
	else {

		Class<?> test = Class.forName(unitTest.getName().split("/")[0]);

		JUnitCore junit = new JUnitCore();
		junit.addListener(new UnitTestRunListener(context, testSuite));

		junit.run(test);
	}
}
 
开发者ID:appronto,项目名称:RedisConnector,代码行数:31,代码来源:TestManager.java


注:本文中的org.junit.runner.JUnitCore.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。