org.junit.runner.Computer Java Examples

The following examples show how to use org.junit.runner.Computer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JUnitTestingUtils.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Run all tests in the supplied test classes according to the policies of
 * the supplied {@link Computer}, using the {@link Runner} configured via
 * {@link RunWith @RunWith} or the default JUnit runner, and assert the
 * expectations of the test execution.
 *
 * <p>To have all tests executed in parallel, supply {@link ParallelComputer#methods()}
 * as the {@code Computer}. To have all tests executed serially, supply
 * {@link Computer#serial()} as the {@code Computer}.
 *
 * @param computer the JUnit {@code Computer} to use
 * @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
 * @param testClasses one or more test classes to run
 */
public static void runTestsAndAssertCounters(Computer computer, int expectedStartedCount, int expectedFailedCount,
		int expectedFinishedCount, int expectedIgnoredCount, int expectedAssumptionFailedCount,
		Class<?>... testClasses) throws Exception {

	JUnitCore junit = new JUnitCore();
	TrackingRunListener listener = new TrackingRunListener();
	junit.addListener(listener);
	junit.run(computer, testClasses);

	// @formatter:off
	assertAll(
		() -> assertEquals(expectedStartedCount, listener.getTestStartedCount(), "tests started"),
		() -> assertEquals(expectedFailedCount, listener.getTestFailureCount(), "tests failed"),
		() -> assertEquals(expectedFinishedCount, listener.getTestFinishedCount(), "tests finished"),
		() -> assertEquals(expectedIgnoredCount, listener.getTestIgnoredCount(), "tests ignored"),
		() -> assertEquals(expectedAssumptionFailedCount, listener.getTestAssumptionFailureCount(), "failed assumptions")
	);
	// @formatter:on
}
 
Example #2
Source File: JUnitTestingUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Run all tests in the supplied test classes according to the policies of
 * the supplied {@link Computer}, using the {@link Runner} configured via
 * {@link RunWith @RunWith} or the default JUnit runner, and assert the
 * expectations of the test execution.
 *
 * <p>To have all tests executed in parallel, supply {@link ParallelComputer#methods()}
 * as the {@code Computer}. To have all tests executed serially, supply
 * {@link Computer#serial()} as the {@code Computer}.
 *
 * @param computer the JUnit {@code Computer} to use
 * @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
 * @param testClasses one or more test classes to run
 */
public static void runTestsAndAssertCounters(Computer computer, int expectedStartedCount, int expectedFailedCount,
		int expectedFinishedCount, int expectedIgnoredCount, int expectedAssumptionFailedCount,
		Class<?>... testClasses) throws Exception {

	JUnitCore junit = new JUnitCore();
	TrackingRunListener listener = new TrackingRunListener();
	junit.addListener(listener);
	junit.run(computer, testClasses);

	// @formatter:off
	assertAll(
		() -> assertEquals(expectedStartedCount, listener.getTestStartedCount(), "tests started"),
		() -> assertEquals(expectedFailedCount, listener.getTestFailureCount(), "tests failed"),
		() -> assertEquals(expectedFinishedCount, listener.getTestFinishedCount(), "tests finished"),
		() -> assertEquals(expectedIgnoredCount, listener.getTestIgnoredCount(), "tests ignored"),
		() -> assertEquals(expectedAssumptionFailedCount, listener.getTestAssumptionFailureCount(), "failed assumptions")
	);
	// @formatter:on
}
 
Example #3
Source File: JUnitRunner.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Throwable {
  Level stdOutLogLevel = Level.INFO;
  Level stdErrLogLevel = Level.WARNING;

  String unparsedStdOutLogLevel = System.getProperty(STD_OUT_LOG_LEVEL_PROPERTY);
  String unparsedStdErrLogLevel = System.getProperty(STD_ERR_LOG_LEVEL_PROPERTY);

  if (unparsedStdOutLogLevel != null) {
    stdOutLogLevel = Level.parse(unparsedStdOutLogLevel);
  }

  if (unparsedStdErrLogLevel != null) {
    stdErrLogLevel = Level.parse(unparsedStdErrLogLevel);
  }

  for (String className : testClassNames) {
    Class<?> testClass = Class.forName(className);

    List<TestResult> results = new ArrayList<>();
    RecordingFilter filter = new RecordingFilter();
    if (mightBeATestClass(testClass)) {
      JUnitCore jUnitCore = new JUnitCore();
      Runner suite = new Computer().getSuite(createRunnerBuilder(), new Class<?>[] {testClass});
      Request request = Request.runner(suite);
      request = request.filterWith(filter);
      jUnitCore.addListener(new TestListener(results, stdOutLogLevel, stdErrLogLevel));
      jUnitCore.run(request);
    }
    // Combine the results with the tests we filtered out
    List<TestResult> actualResults = combineResults(results, filter.filteredOut);
    writeResult(className, actualResults);
  }
}
 
Example #4
Source File: ParallelComputer.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public static Computer classes() {
    return new ParallelComputer(true, false);
}
 
Example #5
Source File: ParallelComputer.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public static Computer methods() {
    return new ParallelComputer(false, true);
}
 
Example #6
Source File: MarathonTestRunner.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
static Computer defaultComputer() {
    return new Computer();
}
 
Example #7
Source File: ParallelIntegrationTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void runTests() {
    final Class<?>[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class };

    JUnitCore.runClasses(new Computer(), classes);
}
 
Example #8
Source File: Spring5JUnit5ParallelIntegrationTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
void givenTwoTestClasses_whenJUnitRunParallel_thenTheTestsExecutingLinear() {
    final Class<?>[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class };

    JUnitCore.runClasses(new Computer(), classes);
}
 
Example #9
Source File: MarathonTestRunner.java    From marathonv5 with Apache License 2.0 2 votes vote down vote up
/**
 * Run the tests contained in <code>classes</code>. Write feedback while the
 * tests are running and write stack traces for all failed tests after all
 * tests complete. This is similar to {@link #main(String[])}, but intended
 * to be used programmatically.
 *
 * @param computer
 *            Helps construct Runners from classes
 * @param classes
 *            Classes in which to find tests
 * @return a {@link Result} describing the details of the test run and the
 *         failed tests.
 */
public static Result runClasses(Computer computer, Class<?>... classes) {
    return new MarathonTestRunner().run(computer, classes);
}
 
Example #10
Source File: MarathonTestRunner.java    From marathonv5 with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}