Java Code Examples for org.junit.runner.notification.Failure#getTrace()

The following examples show how to use org.junit.runner.notification.Failure#getTrace() . 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: InstrumentationResultPrinter.java    From android-test with Apache License 2.0 6 votes vote down vote up
private void reportFailure(Failure failure) {
  String trace = failure.getTrace();
  if (trace.length() > MAX_TRACE_SIZE) {
    // Since AJUR needs to report failures back to AM via a binder IPC, we need to make sure that
    // we don't exceed the Binder transaction limit - which is 1MB per process.
    Log.w(
        TAG,
        String.format("Stack trace too long, trimmed to first %s characters.", MAX_TRACE_SIZE));
    trace = trace.substring(0, MAX_TRACE_SIZE) + "\n";
  }
  testResult.putString(REPORT_KEY_STACK, trace);
  // pretty printing
  testResult.putString(
      Instrumentation.REPORT_KEY_STREAMRESULT,
      String.format(
          "\nError in %s:\n%s", failure.getDescription().getDisplayName(), failure.getTrace()));
}
 
Example 2
Source File: SMTestSender.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void testFailure(Failure failure) throws Exception {
  final String failureMessage = failure.getMessage();
  final String trace = failure.getTrace();
  final Map attrs = new HashMap();
  attrs.put("name", getMethodName(failure.getDescription()));
  attrs.put("message", failureMessage != null ? failureMessage : "");
  final ComparisonFailureData notification = createExceptionNotification(failure.getException());
  if (notification != null) {
    attrs.put("expected", notification.getExpected());
    attrs.put("actual", notification.getActual());

    final int failureIdx = trace.indexOf(failureMessage);
    attrs.put("details", failureIdx > -1 ? trace.substring(failureIdx + failureMessage.length()) : trace);
  }
  else {
    attrs.put("details", trace);
    attrs.put("error", "true");
  }

  System.out.println(ServiceMessage.asString(ServiceMessageTypes.TEST_FAILED, attrs));
}
 
Example 3
Source File: TestSeedFromUncaught.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Verify super method calls on {@link LuceneTestCase#setUp()}.
 */
@Test
public void testUncaughtDumpsSeed() {
  Result result = JUnitCore.runClasses(ThrowInUncaught.class);
  assertFailureCount(1, result);
  Failure f = result.getFailures().get(0);
  String trace = f.getTrace();
  Assert.assertTrue(trace.contains("SeedInfo.seed("));
  Assert.assertTrue(trace.contains("foobar"));
}
 
Example 4
Source File: JUnitTeamcityReporter.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
@Override
public void testFailure(Failure failure) {
    if (failure.getTrace() != null && !failure.getTrace().isEmpty())
        print(failure.getTrace());
    println("##teamcity[testFailed flowId='%s' name='%s' message='%s' details='%s']",
            flowId,
            getTestName(failure.getDescription()),
            "failed",
            "");
    testFinished(failure.getDescription());
}
 
Example 5
Source File: ProgressLoggerListener.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
@Override
public void testFailure(Failure failure) throws Exception {
    String trace = "";
    if (failure.getTrace() != null && !failure.getTrace().isEmpty()) {
        trace = failure.getTrace();
    }
    report("test Failed '%s' message='%s' details='%s'",
            getTestName(failure.getDescription()),
            "failed",
            trace);
    testFinished(failure.getDescription());
}
 
Example 6
Source File: TestEngine.java    From restcommander with Apache License 2.0 5 votes vote down vote up
@Override
public void testFailure(Failure failure) throws Exception {

    if (current == null) {
        // The test probably failed before it could start, ie in @BeforeClass
        current = new TestResult();
        results.add(current); // must add it here since testFinished() never was called.
        current.name = "Before any test started, maybe in @BeforeClass?";
        current.time = System.currentTimeMillis();
    }

    if (failure.getException() instanceof AssertionError) {
        current.error = "Failure, " + failure.getMessage();
    } else {
        current.error = "A " + failure.getException().getClass().getName() + " has been caught, " + failure.getMessage();
        current.trace = failure.getTrace();
    }
    for (StackTraceElement stackTraceElement : failure.getException().getStackTrace()) {
        if (stackTraceElement.getClassName().equals(className)) {
            current.sourceInfos = "In " + Play.classes.getApplicationClass(className).javaFile.relativePath() + ", line " + stackTraceElement.getLineNumber();
            current.sourceCode = Play.classes.getApplicationClass(className).javaSource.split("\n")[stackTraceElement.getLineNumber() - 1];
            current.sourceFile = Play.classes.getApplicationClass(className).javaFile.relativePath();
            current.sourceLine = stackTraceElement.getLineNumber();
        }
    }
    current.passed = false;
    results.passed = false;
}
 
Example 7
Source File: IltConsumerJUnitListener.java    From joynr with Apache License 2.0 5 votes vote down vote up
public void testFailure(Failure failure) {
    String fullTestClassName;
    String baseTestClassName;

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

    Description description = failure.getDescription();
    printDescription(description, 1);
    logger.info("- failure.getException() = " + failure.getException());
    logger.info("- failure.getMessage() = " + failure.getMessage());
    logger.info("- failure.getTestHeader() = " + failure.getTestHeader());
    logger.info("- failure.getTrace() = " + failure.getTrace());

    if (description == null || description.getDisplayName() == null) {
        logger.info("<<< testFinished called");
        return;
    }

    // should have been created already in previous call to testStarted
    TestSuiteResultsStore store = getStore(description);

    TestCaseFailure testCaseFailure = new TestCaseFailure(failure.getMessage(), // message
                                                          failure.getException().toString(), // type
                                                          failure.getTrace() // text
    );
    TestCaseResult testCaseResult = new TestCaseResult(getTestCaseName(description),
                                                       getTestSuiteClassName(description),
                                                       null, // test not finished yet, will be updated later
                                                       "failed", // status
                                                       testCaseFailure, // failure
                                                       null // no systemOut
    );
    store.testCaseResults.add(testCaseResult);
    store.failures++;
    // everything else will be done in testFinished, which is also
    // called for failed tests as well.

    logger.info("<<< testFailure called");
}
 
Example 8
Source File: IltConsumerJUnitListener.java    From joynr with Apache License 2.0 5 votes vote down vote up
@Override
public void testFailure(Failure failure) {
    logger.info(">>> testFailure called");

    Description description = failure.getDescription();
    printDescription(description, 1);
    logger.info("- failure.getException() = " + failure.getException());
    logger.info("- failure.getMessage() = " + failure.getMessage());
    logger.info("- failure.getTestHeader() = " + failure.getTestHeader());
    logger.info("- failure.getTrace() = " + failure.getTrace());

    if (description == null || description.getDisplayName() == null) {
        logger.info("<<< testFinished called");
        return;
    }

    // should have been created already in previous call to testStarted
    TestSuiteResultsStore store = getStore(description);

    TestCaseFailure testCaseFailure = new TestCaseFailure(failure.getMessage(), // message
                                                          failure.getException().toString(), // type
                                                          failure.getTrace() // text
    );
    TestCaseResult testCaseResult = new TestCaseResult(getTestCaseName(description),
                                                       getTestSuiteClassName(description),
                                                       null, // test not finished yet, will be updated later
                                                       "failed", // status
                                                       testCaseFailure, // failure
                                                       null // no systemOut
    );
    store.testCaseResults.add(testCaseResult);
    store.failures++;
    // everything else will be done in testFinished, which is also
    // called for failed tests as well.

    logger.info("<<< testFailure called");
}
 
Example 9
Source File: ParcelableFailure.java    From android-test with Apache License 2.0 4 votes vote down vote up
public ParcelableFailure(Failure failure) {
  this.description = new ParcelableDescription(failure.getDescription());
  this.trace = failure.getTrace();
}