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

The following examples show how to use org.junit.runner.notification.Failure#getMessage() . 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: 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 2
Source File: TimedOutTestsListener.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Override
public void testFailure(Failure failure) throws Exception {
  if (failure != null && failure.getMessage() != null
      && failure.getMessage().startsWith(TEST_TIMED_OUT_PREFIX)) {
    output.println("====> TEST TIMED OUT. PRINTING THREAD DUMP. <====");
    output.println();
    output.print(buildThreadDiagnosticString());
  }
}
 
Example 3
Source File: TimedOutTestsListener.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void testFailure(Failure failure) throws Exception {
  if (failure != null && failure.getMessage() != null 
      && failure.getMessage().startsWith(TEST_TIMED_OUT_PREFIX)) {
    output.println("====> TEST TIMED OUT. PRINTING THREAD DUMP. <====");
    output.println();
    output.print(buildThreadDiagnosticString());
  }
}
 
Example 4
Source File: TimedOutTestsListener.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void testFailure(Failure failure) throws Exception {
  if (failure != null && failure.getMessage() != null 
      && failure.getMessage().startsWith(TEST_TIMED_OUT_PREFIX)) {
    output.println("====> TEST TIMED OUT. PRINTING THREAD DUMP. <====");
    output.println();
    output.print(buildThreadDiagnosticString());
  }
}
 
Example 5
Source File: TimedOutTestsListener.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
public void testFailure(Failure failure) throws Exception {
    if (failure != null && failure.getMessage() != null && failure.getMessage().startsWith(TEST_TIMED_OUT_PREFIX)) {
        output.println("====> TEST TIMED OUT. PRINTING THREAD DUMP. <====");
        output.println();
        output.print(buildThreadDiagnosticString());
    }
}
 
Example 6
Source File: TimedOutTestsListener.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void testFailure(Failure failure) throws Exception {
    if (failure != null && failure.getMessage() != null && failure.getMessage().startsWith(TEST_TIMED_OUT_PREFIX)) {
        output.println("====> TEST TIMED OUT. PRINTING THREAD DUMP. <====");
        output.println();
        output.print(buildThreadDiagnosticString());
        output.flush();
    }
}
 
Example 7
Source File: IsFailure.java    From spectrum with MIT License 5 votes vote down vote up
@Override
protected boolean matchesSafely(final Failure item, final Description mismatchDescription) {
  final String actualMethodName = getMethodName(item);
  final Throwable exception = item.getException();
  final Class<? extends Throwable> actualExceptionType =
      exception == null ? null : exception.getClass();
  final String actualMessage = exception == null ? null : item.getMessage();

  describeTo(mismatchDescription, actualMethodName, actualExceptionType, actualMessage);

  return this.methodName.equals(actualMethodName)
      && this.exceptionType.isAssignableFrom(actualExceptionType)
      && this.failureMessage.equals(actualMessage);
}
 
Example 8
Source File: TimedOutTestsListener.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void testFailure(Failure failure) throws Exception {
  if (failure != null && failure.getMessage() != null
      && failure.getMessage().startsWith(TEST_TIMED_OUT_PREFIX)) {
    output.println("====> TEST TIMED OUT. PRINTING THREAD DUMP. <====");
    output.println();
    output.print(buildThreadDiagnosticString());
  }
  output.flush();
}
 
Example 9
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 10
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 11
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 12
Source File: TestExecuterCLI.java    From muJava with Apache License 2.0 4 votes vote down vote up
/**
 * compute the result of a test under the original program
 */
public void computeOriginalTestResults() {
	Debug.println("\n\n======================================== Generating Original Test Results ========================================");
	try {
		// initialize the original results to "pass"
		// later the results of the failed test cases will be updated
		for (int k = 0; k < testCases.length; k++) {
			Annotation[] annotations = testCases[k].getDeclaredAnnotations();
			for (Annotation annotation : annotations) {
				// System.out.println("name: " + testCases[k].getName() +
				// annotation.toString() +
				// annotation.toString().indexOf("@org.junit.Test"));
				if (annotation.toString().indexOf("@org.junit.Test") != -1) {
					// killed_mutants[k]= ""; // At first, no mutants are
					// killed by each test case
					originalResults.put(testCases[k].getName(), "pass");
					junitTests.add(testCases[k].getName());
					finalTestResults.put(testCases[k].getName(), "");
					continue;
				}
			}
		}

		JUnitCore jCore = new JUnitCore();
		// result = jCore.runMain(new RealSystem(), "VMTEST1");
		result = jCore.run(original_executer);

		// get the failure report and update the original result of the test
		// with the failures
		List<Failure> listOfFailure = result.getFailures();
		for (Failure failure : listOfFailure) {
			String nameOfTest = failure.getTestHeader().substring(0, failure.getTestHeader().indexOf("("));
			String testSourceName = testSet + "." + nameOfTest;

			// System.out.println("failure message: " + failure.getMessage()
			// + failure.getMessage().equals(""));
			String[] sb = failure.getTrace().split("\\n");
			String lineNumber = "";
			for (int i = 0; i < sb.length; i++) {
				if (sb[i].indexOf(testSourceName) != -1) {
					lineNumber = sb[i].substring(sb[i].indexOf(":") + 1, sb[i].indexOf(")"));
				}
			}

			// put the failure messages into the test results
			if (failure.getMessage() == null)
				originalResults.put(nameOfTest, nameOfTest + ": " + lineNumber + "; " + "fail");
			else {
				if (failure.getMessage().equals(""))
					originalResults.put(nameOfTest, nameOfTest + ": " + lineNumber + "; " + "fail");
				else
					originalResults.put(nameOfTest, nameOfTest + ": " + lineNumber + "; " + failure.getMessage());
			}

		}
		Util.DebugPrint(originalResults.toString());

		// System.out.println(System.getProperty("user.dir"));
		// System.out.println(System.getProperty("java.class.path"));
		// System.out.println(System.getProperty("java.library.path"));

	} catch (Exception e) {
		System.out.println(e.getMessage());
		e.printStackTrace();

		// original_results[k] = e.getCause().getClass().getName()+" : "
		// +e.getCause().getMessage();
		// Debug.println("Result for " + testName + "  :  "
		// +original_results[k] );
		// Debug.println(" [warining] " + testName +
		// " generate exception as a result " );

		// ----------------------------------

	} finally {
		// originalResultFileRead();
	}
}