org.junit.runner.Result Java Examples

The following examples show how to use org.junit.runner.Result. 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: BundleJUnitUtilsTest.java    From android-test with Apache License 2.0 7 votes vote down vote up
@Test
public void fromResult_failure() throws Exception {
  Class<SampleJUnitTest> testClass = SampleJUnitTest.class;
  Description jUnitDescription = Description.createTestDescription(testClass, "sampleTest");
  Throwable throwable = new RuntimeException("Your test is bad and you should feel bad.");
  Failure jUnitFailure = new Failure(jUnitDescription, throwable);

  Result jUnitResult = new Result();
  RunListener jUnitListener = jUnitResult.createListener();
  jUnitListener.testRunStarted(jUnitDescription);
  jUnitListener.testStarted(jUnitDescription);
  jUnitListener.testFailure(jUnitFailure);
  jUnitListener.testFinished(jUnitDescription);

  ParcelableResult parcelableResult =
      BundleJUnitUtils.getResult(parcelBundle(BundleJUnitUtils.getBundleFromResult(jUnitResult)));

  assertThat(parcelableResult.wasSuccessful(), is(jUnitResult.wasSuccessful()));
  assertThat(parcelableResult.getFailureCount(), is(jUnitResult.getFailureCount()));
  compareFailure(parcelableResult.getFailures().get(0), jUnitResult.getFailures().get(0));
}
 
Example #2
Source File: MutantSearchSpaceExplorator.java    From metamutator with GNU General Public License v3.0 7 votes vote down vote up
/**
 * this function launch a parallel class
 * @param classes
 * @param core
 * @return Core Result or null on blocking
 */
public static Result runWithThread(Class<?> classes, JUnitCore core) {
	int i = 0;
	// Define Runner
	RunnerThreaded runner = new RunnerThreaded(classes,core);
	
	runner.start();
	try {
		runner.join();
	} catch (InterruptedException e) {
		throw new RuntimeException("interrupted");
	}
	if (runner.getResult()==null) {
		throw new RuntimeException("interrupted");
	}
	
	return runner.getResult();
}
 
Example #3
Source File: ConstraintModelBuilder.java    From nopol with GNU General Public License v2.0 6 votes vote down vote up
private boolean isSynthesisPossible(final Result firstResultWithFalse, final Result secondResultWithTrue) {
  	// this method is a key optimization in Nopol
// it enables to not start the synthesis when we are sure that it is not possible
// only based on the observed test outcomes with angelic values

      Collection<Description> testFailuresWithFalse = TestSuiteExecution.collectDescription(firstResultWithFalse.getFailures());
      Collection<Description> testFailuresWithTrue = TestSuiteExecution.collectDescription(secondResultWithTrue.getFailures());

      // contract: all test failures must either in testFailuresWithFalse or in secondFailures
// removes from testFailuresWithFalse all of its elements that are not contained in testFailuresWithTrue
// consequently, it remains the elements that are always failing
Collection<Description> testsThatAreAlwasyFailing = new ArrayList<>(testFailuresWithFalse);
testsThatAreAlwasyFailing.retainAll(testFailuresWithTrue);

      boolean synthesisIsPossible = testsThatAreAlwasyFailing.isEmpty();

      // some logging
      int nbFirstSuccess = firstResultWithFalse.getRunCount() - firstResultWithFalse.getFailureCount();
      int nbSecondSuccess = secondResultWithTrue.getRunCount() - secondResultWithTrue.getFailureCount();
      if (!synthesisIsPossible || (nbFirstSuccess == 0 && nbSecondSuccess == 0)) {
          Logger testsOutput = LoggerFactory.getLogger("tests.output");
          testsOutput.debug("Failing tests with false: \n{}", firstResultWithFalse.getFailures());
          testsOutput.debug("Failing tests with true: \n{}", secondResultWithTrue.getFailures());
      }
      return synthesisIsPossible;
  }
 
Example #4
Source File: DelegateRunNotifier.java    From buck with Apache License 2.0 6 votes vote down vote up
DelegateRunNotifier(Runner runner, RunNotifier delegate, long defaultTestTimeoutMillis) {
  this.runner = runner;
  this.delegate = delegate;
  this.finishedTests = new HashSet<Description>();
  this.defaultTestTimeoutMillis = defaultTestTimeoutMillis;
  this.timer = new Timer();
  this.hasTestThatExceededTimeout = new AtomicBoolean(false);

  // Because our fireTestRunFinished() does not seem to get invoked, we listen for the
  // delegate to fire a testRunFinished event so we can dispose of the timer.
  delegate.addListener(
      new RunListener() {
        @Override
        public void testRunFinished(Result result) {
          onTestRunFinished();
        }
      });
}
 
Example #5
Source File: DefaultServer.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
private static void runInternal(final RunNotifier notifier) {
    if (openssl && OPENSSL_FAILURE != null) {
        throw new RuntimeException(OPENSSL_FAILURE);
    }
    if (first) {
        first = false;
        undertow = Undertow.builder()
                .setHandler(rootHandler)
                .addHttpListener(getHostPort(DEFAULT), getHostAddress(DEFAULT))
                .build();
        undertow.start();
        notifier.addListener(new RunListener() {
            @Override
            public void testRunFinished(Result result) throws Exception {
                super.testRunFinished(result);
                undertow.stop();
                clientGroup.shutdownGracefully();
            }
        });
    }
}
 
Example #6
Source File: Outcome.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
public Outcome(Result result, String digest_) {
  // Constructs an Outcome from a JUnit result.
  // Only PASS/FAIL outcomes can be made this way: if a test times out
  // or crashes the JVM, there won't be a JUnit result to base the Outcome on.
  // In those cases, use createTimeout or createCrash.
  digest = digest_;
  coveredMutants = new ArrayList<Integer>();
  if (result.wasSuccessful()) {
    type = Type.PASS;
    runTime = result.getRunTime();
    stackTrace = "";
  } else {
    type = Type.FAIL;
    runTime = result.getRunTime();
    stackTrace = normalizeStackTrace(result.getFailures().get(0).getTrace());
  }
}
 
Example #7
Source File: FailTestOnLeakRunListener.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
/**
 * Can be overridden to customize the failure string message.
 */
protected @NonNull
String buildLeakDetectedMessage(
        @NonNull List<InstrumentationLeakResults.Result> detectedLeaks) {
    StringBuilder failureMessage = new StringBuilder();
    failureMessage.append(
            "Test failed because memory leaks were detected, see leak traces below.\n");
    failureMessage.append(SEPARATOR);

    Context context = getInstrumentation().getContext();
    for (InstrumentationLeakResults.Result detectedLeak : detectedLeaks) {
        failureMessage.append(
                LeakCanary.leakInfo(context, detectedLeak.heapDump, detectedLeak.analysisResult, true));
        failureMessage.append(SEPARATOR);
    }

    return failureMessage.toString();
}
 
Example #8
Source File: PropertyIndexingTests.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #9
Source File: TestCasesListener.java    From nopol with GNU General Public License v2.0 6 votes vote down vote up
private void logTestRunFinished(Result result) {
    Collection<String> lines = MetaList.newArrayList();
    lines.add(format("Tests run finished (%d ms)", result.getRunTime()));
    lines.add("<> Total tests run: " + result.getRunCount());
    lines.add("<> Ignored tests: " + result.getIgnoreCount());
    lines.add("<> Failed tests: " + result.getFailureCount());
    for (Failure failure : result.getFailures()) {
        lines.add("~ " + failure.getTestHeader());
        lines.add("[" + failure.getMessage() + "]");
        Throwable exception = failure.getException();
        lines.add(exception.toString());
        for (int i = 0; i <= 5; i += 1) {
            StackTraceElement element = exception.getStackTrace()[i];
            lines.add("    at " + element.toString());
        }
    }
    //logDebug(logger(), lines);
}
 
Example #10
Source File: TestRequestBuilderTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
/**
 * Test case where method has both a size annotation and suppress annotation. Expect suppress to
 * overrule the size.
 */
@Test
public void testSizeWithSuppress() {
  Request request =
      builder
          .addTestClass(SampleSizeWithSuppress.class.getName())
          .addTestClass(SampleJUnit3Test.class.getName())
          .addTestSizeFilter(TestSize.SMALL)
          .build();
  JUnitCore testRunner = new JUnitCore();
  MyRunListener l = new MyRunListener();
  testRunner.addListener(l);
  Result r = testRunner.run(request);
  Assert.assertEquals(2, r.getRunCount());
  Assert.assertEquals(2, l.testCount);
}
 
Example #11
Source File: ZeroCodePackageRunner.java    From zerocode with Apache License 2.0 6 votes vote down vote up
private void handleNoRunListenerReport(ZeroCodeTestReportListener reportListener) {
    if (CHARTS_AND_CSV.equals(getProperty(ZEROCODE_JUNIT))) {
        /**
         * Gradle does not support JUnit RunListener. Hence Zerocode gracefully handled this
         * upon request from Gradle users. But this is not limited to Gradle, anywhere you
         * want to bypass the JUnit RunListener, you can achieve this way.
         * See README for details.
         *
         * There are number of tickets opened for this, but not yet fixed.
         * - https://discuss.gradle.org/t/testrunfinished-not-run-in-junit-integration/14644
         * - https://github.com/gradle/gradle/issues/842
         * - many more related tickets.
         */
        LOGGER.debug("Bypassed JUnit RunListener [as configured by the build tool] to generate useful reports...");
        reportListener.testRunFinished(new Result());
    }
}
 
Example #12
Source File: IltConsumerJUnitListener.java    From joynr with Apache License 2.0 6 votes vote down vote up
@Override
public void testRunFinished(Result result) {
    ArrayList<TestSuiteResult> testSuiteResults = new ArrayList<TestSuiteResult>();

    logger.info(">>> testRunFinished called");

    logger.info("testRunFinished  testSuitesMap.size() = " + testSuitesMap.size());
    for (Map.Entry<String, TestSuiteResultsStore> testSuiteEntry : testSuitesMap.entrySet()) {
        logger.info("testRunFinished testSuiteName = " + testSuiteEntry.getKey());
        TestSuiteResultsStore store = testSuiteEntry.getValue();
        TestSuiteResult testSuiteResult = new TestSuiteResult(testSuiteEntry.getKey(),
                                                              getFormattedDuration(store.consumedTime),
                                                              store.tests,
                                                              store.errors,
                                                              store.skipped,
                                                              store.failures,
                                                              store.testCaseResults.toArray(new TestCaseResult[store.testCaseResults.size()]));

        testSuiteResults.add(testSuiteResult);
    }
    logger.info("testRunFinished  after for loop");

    testResult = new TestResult(testSuiteResults.toArray(new TestSuiteResult[testSuiteResults.size()]));

    logger.info("<<< testRunFinished called");
}
 
Example #13
Source File: TestListener.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * Called when all tests have finished. Prints to stdout if the tests were successful or not. If
 * not, it also prints the number of failed test cases. Finally, it prints the number of
 * ignored test cases.
 *
 * @param result the summary of the test run, including all the tests that failed
 */
@Override
public void testRunFinished(Result result) throws Exception {
  if (result.wasSuccessful()) {
    System.out.println("Successfully finished running "
        + formatTestCaseCount(result.getRunCount()) + " in " + result.getRunTime() + " ms.");
  } else {
    System.out.println("Finished running " + formatTestCaseCount(result.getRunCount())
        + " in " + result.getRunTime() + " ms.");
    int failureCount = result.getFailureCount();
    if (failureCount == 1) {
      System.out.println("There was 1 failed test.");
    } else {
      System.out.println("There were " + failureCount + " failed tests.");
    }
  }
  int ignoredCount = result.getIgnoreCount();
  if (ignoredCount == 1) {
    System.out.println(result.getIgnoreCount() + " test case was ignored.");
  } else if (ignoredCount > 1) {
    System.out.println(result.getIgnoreCount() + " test cases were ignored.");
  }
}
 
Example #14
Source File: TestRequestBuilderTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
/** Test provided both include and exclude annotations. */
@Test
public void testTestSizeFilter_annotationAndNotAnnotationAtMethod() {
  Request request =
      builder
          .addAnnotationInclusionFilter(SmallTest.class.getName())
          .addAnnotationExclusionFilter(FlakyTest.class.getName())
          .addTestClass(SampleRunnerFilterSizeTest.class.getName())
          .addTestClass(SampleMultipleAnnotation.class.getName())
          .build();
  JUnitCore testRunner = new JUnitCore();
  Result result = testRunner.run(request);
  // expect 1 test that passed.
  Assert.assertEquals(1, result.getRunCount());
  Assert.assertEquals(0, result.getFailureCount());
}
 
Example #15
Source File: NeodymiumWebDriverTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testValidateReuseWebDriver()
{
    // XVFB or a display needed
    Result result = JUnitCore.runClasses(ValidateReuseWebDriver.class);
    checkPass(result, 2, 0, 0);
}
 
Example #16
Source File: TestCaseRunner.java    From s3mper with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws ClassNotFoundException {
    Request testCase = Request.method(Class.forName(args[0]), args[1]);
    
    JUnitCore core = new JUnitCore();
    
    Result result = core.run(testCase);
    
    for(Failure f: result.getFailures()) {
        System.out.println(f.getMessage());
        f.getException().printStackTrace();
    }
    System.exit(result.wasSuccessful() ? 0 : 1);
}
 
Example #17
Source File: JUnitTest.java    From vertx-unit with Apache License 2.0 5 votes vote down vote up
@Test
public void testAfterClass() {
  Result result = run(AfterClassTestSuite.class);
  assertEquals(1, result.getRunCount());
  assertEquals(0, result.getFailureCount());
  assertEquals(Arrays.asList("test", "afterClass"), AfterClassTestSuite.events);
}
 
Example #18
Source File: TestRequestBuilderTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
/** Test filtering a parameterized method */
@Ignore // TODO(b/26110951) not supported yet
@Test
public void testParameterizedMethods() throws Exception {
  Request request =
      builder.addTestMethod(ParameterizedTest.class.getName(), "testParameterized").build();
  JUnitCore testRunner = new JUnitCore();
  Result result = testRunner.run(request);
  Assert.assertEquals(3, result.getRunCount());
}
 
Example #19
Source File: OrchestratedInstrumentationListenerTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);
  listener = new OrchestratedInstrumentationListener(this);
  listener.odoCallback = mockCallback;

  Class<SampleJUnitTest> testClass = SampleJUnitTest.class;
  jUnitDescription = Description.createTestDescription(testClass, "sampleTest");
  jUnitFailure = new Failure(jUnitDescription, new Throwable("error"));
  jUnitResult = new Result();
  RunListener jUnitListener = jUnitResult.createListener();
  jUnitListener.testRunStarted(jUnitDescription);
  jUnitListener.testStarted(jUnitDescription);
  jUnitListener.testFinished(jUnitDescription);
}
 
Example #20
Source File: TestFailIfDirectoryNotClosed.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailIfDirectoryNotClosed() {
  Result r = JUnitCore.runClasses(Nested1.class);
  RandomizedTest.assumeTrue("Ignoring nested test, very likely zombie threads present.", 
      r.getIgnoreCount() == 0);
  assertFailureCount(1, r);
  Assert.assertTrue(r.getFailures().get(0).toString().contains("Resource in scope SUITE failed to close"));
}
 
Example #21
Source File: TestDataStatementTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testPackageTestDataInheritance()
{
    // test inheritance of package test data
    Result result = JUnitCore.runClasses(PackageTestDataInheritance.class);
    checkPass(result, 1, 0, 0);
}
 
Example #22
Source File: JUnitTest.java    From vertx-unit with Apache License 2.0 5 votes vote down vote up
@Test
public void testBefore() {
  Result result = run(BeforeTestSuite.class);
  assertEquals(1, result.getRunCount());
  assertEquals(0, result.getFailureCount());
  assertEquals(Arrays.asList("before", "test"), BeforeTestSuite.events);
}
 
Example #23
Source File: TestDataStatementTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testCanReadDataSetCSV()
{
    // test data set csv is read
    Result result = JUnitCore.runClasses(CanReadDataSetCSV.class);
    checkPass(result, 1, 0, 0);
}
 
Example #24
Source File: JUnit4RunnerTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void testRunFailsWithAllTestsFilteredOut() {
  config = createConfig("doesNotMatchAnything");
  JUnit4Runner runner = createRunner(SampleSuite.class);
  Result result = runner.run();

  assertThat(result.getRunCount()).isEqualTo(1);
  assertThat(result.getFailureCount()).isEqualTo(1);
  assertThat(result.getIgnoreCount()).isEqualTo(0);
  assertThat(result.getFailures().get(0).getMessage()).contains("No tests found");
}
 
Example #25
Source File: End2EndTestDriver.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void testRunFinished(Result result) {
    printHeader(result.getRunTime());
    printFailures(result);
    printSummary(result);
    fWriter.println();
    printFooter(result);
}
 
Example #26
Source File: TestDataStatementTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testCanReadPackageDataJson()
{
    // test package test data json is read
    Result result = JUnitCore.runClasses(CanReadPackageDataJson.class);
    checkPass(result, 1, 0, 0);
}
 
Example #27
Source File: NeodymiumContextTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testIsSite()
{
    // test the isSite function
    Result result = JUnitCore.runClasses(IsSiteTests.class);
    checkPass(result, 10, 0, 0);
}
 
Example #28
Source File: EnvironmentAndBrowserConfigurationTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testRunningABrowserWithoutAEnvironmentConfiguration()
{
    // test environment configuration
    Result result = JUnitCore.runClasses(BrowserWithoutAvailableEnvironment.class);
    checkFail(result, 1, 0, 1, "No properties found for test environment: \"" + ENVIRONMENTNAME + "\"");
}
 
Example #29
Source File: EnvironmentAndBrowserConfigurationTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testOverridingEnvironmentsAndBrowsers()
{
    // test environment configuration
    Result result = JUnitCore.runClasses(EnvironmentAndBrowserConfiguration.class);
    checkPass(result, 5, 0, 0);
}
 
Example #30
Source File: TestDataStatementTest.java    From neodymium-library with MIT License 5 votes vote down vote up
@Test
public void testForceOfNoneDataSets() throws Exception
{
    Result result = JUnitCore.runClasses(ForceOfNoneDataSets.class);
    checkFail(result, 1, 0, 1,
              "java.lang.IllegalArgumentException: Method 'test1' is marked to be run with data set index 2, but there are only 0");
}