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


Java JUnitCore.addListener方法代码示例

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


在下文中一共展示了JUnitCore.addListener方法的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: 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

示例3: 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

示例4: testSystem

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Test
public void testSystem() throws Throwable {
    Computer computer = new Computer();
    JUnitCore jUnitCore = new JUnitCore();

    ByteArrayOutputStream capture = new ByteArrayOutputStream();
    final PrintStream printStream = new PrintStream(capture);
    TextListener listener = new TextListener(printStream);
    jUnitCore.addListener(listener);

    PrintStream systemOut = System.out;
    System.setOut(printStream);
    try {
        jUnitCore.run(computer, ExampleTest.class);
    } finally {
        System.setOut(systemOut);
    }

    String output = capture.toString("UTF-8");
    output = normalizeOutput(output);

    String expectedOutput = getResource("/CompositeTest.testSystem.expected.txt");
    Assert.assertEquals(expectedOutput, output);
}
 
开发者ID:diosmosis,项目名称:junit-composite-runner,代码行数:25,代码来源:CompositeRunnerTest.java

示例5: shouldReportDescriptionsinCorrectOrder

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Test
public void shouldReportDescriptionsinCorrectOrder() {
    JUnitCore jUnit = new JUnitCore();
    jUnit.addListener(new RunListener() {
        @Override
        public void testRunStarted(Description description) throws Exception {
            suiteDescription = description;
        }
    });
    jUnit.run(CuppaRunnerTest.TestsAndTestBlocks.class);

    List<Description> rootDescriptionChildren = suiteDescription
            .getChildren().get(0).getChildren().get(0).getChildren();
    assertThat(rootDescriptionChildren).hasSize(3);
    assertThat(rootDescriptionChildren.get(0).getDisplayName()).startsWith("a");
    assertThat(rootDescriptionChildren.get(1).getDisplayName()).startsWith("b");
    assertThat(rootDescriptionChildren.get(2).getDisplayName()).startsWith("when c");
    assertThat(rootDescriptionChildren.get(2).getChildren().get(0).getDisplayName()).startsWith("d");
}
 
开发者ID:cuppa-framework,项目名称:cuppa,代码行数:20,代码来源:CuppaRunnerTest.java

示例6: run

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
public boolean run() throws IOException {
    try {
        m_dir = "testout/junit-" + m_timestamp + "/" + m_testClazz.getCanonicalName() + "/";
        new File(m_dir).mkdirs();

        // redirect std out/err to files
        m_out.addOutputStream(new File(m_dir + "fulloutput.txt"));
        System.setOut(new PrintStream(m_out, true));
        System.setErr(new PrintStream(m_out, true));

        JUnitCore junit = new JUnitCore();
        junit.addListener(this);
        Result r = junit.run(m_testClazz);
        STDOUT.printf("RESULTS: %d/%d\n", r.getRunCount() - r.getFailureCount(), r.getRunCount());
        return true;
    }
    catch (Exception e) {
        return false;
    }
    finally {
        m_out.flush();
        System.setOut(STDOUT);
        System.setErr(STDERR);
        m_out.close();
    }
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:27,代码来源:VoltTestRunner.java

示例7: prepare

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Before
public void prepare() {
    results = new AllureResultsWriterStub();
    AllureLifecycle lifecycle = new AllureLifecycle(results);
    StepsAspects.setLifecycle(lifecycle);
    AllureJunit4 listener = new AllureJunit4(lifecycle);
    core = new JUnitCore();
    core.addListener(listener);
}
 
开发者ID:allure-framework,项目名称:allure-java,代码行数:10,代码来源:FeatureCombinationsTest.java

示例8: 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

示例9: 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

示例10: run

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
/**
 * Runs the test classes given in {@param classes}.
 * @returns Zero if all tests pass, non-zero otherwise.
 */
public static int run(String[] classes, RunListener listener, DopplJunitListener dopplListener)
{
    try
    {
        JUnitCore junitCore = new JUnitCore();

        if(listener != null)
            junitCore.addListener(listener);

        boolean hasError = false;
        Result result;

        List<ResultContainer> resultList = new ArrayList<>(classes.length);
        for (String c : classes) {

            System.out.println("\n\n********** Running "+ c +" **********");

            if(dopplListener != null)
                dopplListener.startRun(c);

            result = runSpecificTest(junitCore, c);

            if(dopplListener != null)
                dopplListener.endRun(c);

            resultList.add(new ResultContainer(result, c));
            hasError = hasError || !result.wasSuccessful();
        }

        return runInner(resultList, hasError);
    }
    catch(ClassNotFoundException e)
    {
        throw new RuntimeException(e);
    }
}
 
开发者ID:doppllib,项目名称:core-doppl,代码行数:41,代码来源:DopplJunitTestHelper.java

示例11: runTests

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
private static Result runTests(Injector injector, Class<?>[] testClasses, Optional<Description> testFilter) throws InitializationError {

    final JUnitCore junit = new JUnitCore();
    junit.addListener(new JUnitRunListener(LOGGER));

    final Request testRequest = Request.runner(new Suite(new GuiceInjectionJUnitRunner(injector), testClasses));
    if (testFilter.isPresent()) {
      return junit.run(testRequest.filterWith(testFilter.get()));
    } else {
      return junit.run(testRequest);
    }
  }
 
开发者ID:atgse,项目名称:sam,代码行数:13,代码来源:TestCommand.java

示例12: 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");

  JUnitCore junit = new JUnitCore();
  junit.addListener(new TextListener(System.out));
  Result result = junit.run(classes);

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

示例13: launchInProcess

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
private static JkTestSuiteResult launchInProcess(Class<?>[] classes,
        boolean printEachTestOnConsole, JunitReportDetail reportDetail, File reportDir,
        boolean restoreSystemOut) {
    final JUnitCore jUnitCore = new JUnitCore();

    if (reportDetail.equals(JunitReportDetail.FULL)) {
        jUnitCore.addListener(new JUnitReportListener(reportDir.toPath()));
    }
    final PrintStream out = System.out;
    final PrintStream err = System.err;
    if (printEachTestOnConsole) {
        jUnitCore.addListener(new JUnitConsoleListener());
    } else if (!JkLog.verbose()) {
        System.setErr(JkUtilsIO.nopPrintStream());
        System.setOut(JkUtilsIO.nopPrintStream());
    }

    final Properties properties = (Properties) System.getProperties().clone();
    final long start = System.nanoTime();
    final Result result;
    try {
        result = jUnitCore.run(classes);
    } finally {
        if (restoreSystemOut) {
            System.setErr(err);
            System.setOut(out);
        }
    }
    final long durationInMillis = JkUtilsTime.durationInMillis(start);
    return JkTestSuiteResult.fromJunit4Result(properties, "all", result, durationInMillis);
}
 
开发者ID:jerkar,项目名称:jerkar,代码行数:32,代码来源:JUnit4TestExecutor.java

示例14: runTestCaseWithMockListener

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
protected RunListener runTestCaseWithMockListener(Class<?> testCase, Description subCase)
        throws InitializationError {
    RunListener listener = Mockito.mock(RunListener.class);
    JUnitCore core = new JUnitCore();
    core.addListener(listener);
    core.run(Request.runner(new TheorySuite(testCase)).filterWith(subCase));
    return listener;
}
 
开发者ID:richard-melvin,项目名称:junit-theory-suite,代码行数:9,代码来源:CustomRunnerTest.java

示例15: shouldReportCorrectDescriptionsOfSuite

import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Test
public void shouldReportCorrectDescriptionsOfSuite() {
    JUnitCore jUnit = new JUnitCore();
    jUnit.addListener(new RunListener() {
        @Override
        public void testRunStarted(Description description) throws Exception {
            suiteDescription = description;
        }
    });
    jUnit.run(CuppaRunnerTest.PassingTest.class);

    assertThat(suiteDescription).isNotNull();
    assertThat(suiteDescription.isSuite()).isTrue();
    assertThat(suiteDescription.getChildren()).hasSize(1);

    Description cuppaDescription = suiteDescription.getChildren().get(0);

    assertThat(cuppaDescription.isSuite()).isTrue();
    assertThat(cuppaDescription.getDisplayName()).isEqualTo(CuppaRunnerTest.PassingTest.class.getName());
    assertThat(cuppaDescription.getChildren()).hasSize(1);

    Description describeDescription = cuppaDescription.getChildren().get(0);

    assertThat(describeDescription.isSuite()).isTrue();
    assertThat(describeDescription.getDisplayName()).isEqualTo("Cuppa");
    assertThat(describeDescription.getChildren()).hasSize(1);

    Description whenDescription = describeDescription.getChildren().get(0);

    assertThat(whenDescription.isSuite()).isTrue();
    assertThat(whenDescription.getDisplayName()).isEqualTo("when running with CuppaRunner");
    assertThat(whenDescription.getChildren()).hasSize(1);

    Description testDescription = whenDescription.getChildren().get(0);

    assertThat(testDescription.isTest()).isTrue();
    assertThat(testDescription.getDisplayName()).isEqualTo("shows a passing test as passing("
            + CuppaRunnerTest.PassingTest.class.getName() + ")");
    assertThat(testDescription.getTestClass()).isEqualTo(CuppaRunnerTest.PassingTest.class);
}
 
开发者ID:cuppa-framework,项目名称:cuppa,代码行数:41,代码来源:CuppaRunnerTest.java


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