Java Code Examples for org.junit.runner.notification.Failure#getException()
The following examples show how to use
org.junit.runner.notification.Failure#getException() .
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: ReproduceInfoPrinter.java From crate with Apache License 2.0 | 6 votes |
@Override public void testFailure(Failure failure) throws Exception { // Ignore assumptions. if (failure.getException() instanceof AssumptionViolatedException) { return; } final String gradlew = Constants.WINDOWS ? "gradlew" : "./gradlew"; final StringBuilder b = new StringBuilder("REPRODUCE WITH: " + gradlew + " "); String task = System.getProperty("tests.task"); // TODO: enforce (intellij still runs the runner?) or use default "test" but that won't work for integ b.append(task); GradleMessageBuilder gradleMessageBuilder = new GradleMessageBuilder(b); gradleMessageBuilder.appendAllOpts(failure.getDescription()); printToErr(b.toString()); }
Example 2
Source File: JUnitRunner.java From h2o-2 with Apache License 2.0 | 6 votes |
public static void main(String[] args) { try { H2O.main(args); TestUtil.stall_till_cloudsize(3); List<Class> tests = JUnitRunner.all(); Result r = org.junit.runner.JUnitCore.runClasses(tests.toArray(new Class[0])); if( r.getFailureCount() == 0 ) { System.out.println("Successfully ran the following tests in " + (r.getRunTime() / 1000) + "s"); for( Class c : tests ) System.out.println(c.getName()); } else { for( Failure f : r.getFailures() ) { System.err.println(f.getDescription()); if( f.getException() != null ) f.getException().printStackTrace(); } } System.exit(r.getFailureCount()); } catch( Throwable t ) { t.printStackTrace(); System.exit(1); } }
Example 3
Source File: TestCasesListener.java From nopol with GNU General Public License v2.0 | 6 votes |
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 4
Source File: TestCasesListener.java From astor with GNU General Public License v2.0 | 6 votes |
private void logTestRunFinished(Result result) { Collection<String> lines = new ArrayList<>(); 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 5
Source File: UnitTestRunListener.java From RestServices with Apache License 2.0 | 5 votes |
@Override public void testFailure(Failure failure) throws java.lang.Exception { boolean isCloudSecurityError = failure.getException() != null && failure.getException() instanceof AccessControlException && ((AccessControlException) failure.getException()).getPermission().getName().equals("accessDeclaredMembers"); UnitTest t = getUnitTest(failure.getDescription()); /** * Test itself failed */ TestManager.LOG.error("Failed test (at step '" + TestManager.instance().getLastReportedStep() + "') " + failure.getDescription().getClassName() + "." + failure.getDescription().getMethodName() + " : " + failure.getMessage(), failure.getException()); testSuite.setTestFailedCount(testSuite.getTestFailedCount() + 1); testSuite.commit(); t.setResult(UnitTestResult._2_Failed); t.setResultMessage(String.format("%s %s: %s\n\n:%s", isCloudSecurityError ? "CLOUD SECURITY EXCEPTION \n\n" + TestManager.CLOUD_SECURITY_ERROR : "FAILED", findProperExceptionLine(failure.getTrace()), failure.getMessage(), failure.getTrace() )); t.setLastStep(TestManager.instance().getLastReportedStep()); t.setLastRun(new Date()); t.commit(); }
Example 6
Source File: NettyClientInteropServlet.java From grpc-java with Apache License 2.0 | 5 votes |
private void doGetHelper(HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); PrintWriter writer = resp.getWriter(); writer.println("Test invoked at: "); writer.println(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss Z") .format(Calendar.getInstance().getTime())); Result result = new JUnitCore().run(Tester.class); if (result.wasSuccessful()) { resp.setStatus(200); writer.println( String.format( "PASS! Tests ran %d, tests ignored %d", result.getRunCount(), result.getIgnoreCount())); } else { resp.setStatus(500); writer.println( String.format( "FAILED! Tests ran %d, tests failed %d, tests ignored %d", result.getRunCount(), result.getFailureCount(), result.getIgnoreCount())); for (Failure failure : result.getFailures()) { writer.println("================================"); writer.println(failure.getTestHeader()); Throwable thrown = failure.getException(); StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); thrown.printStackTrace(printWriter); writer.println(stringWriter); } } }
Example 7
Source File: SharedPinpointPluginTest.java From pinpoint with Apache License 2.0 | 5 votes |
private String failureToString(Failure failure) { StringBuilder builder = new StringBuilder(); builder.append(failure.getTestHeader()); builder.append(JUNIT_OUTPUT_DELIMITER); Throwable t = failure.getException(); while (true) { builder.append(t.getClass().getName()); builder.append(JUNIT_OUTPUT_DELIMITER); builder.append(t.getMessage()); builder.append(JUNIT_OUTPUT_DELIMITER); for (StackTraceElement e : failure.getException().getStackTrace()) { builder.append(e.getClassName()); builder.append(','); builder.append(e.getMethodName()); builder.append(','); builder.append(e.getFileName()); builder.append(','); builder.append(e.getLineNumber()); builder.append(JUNIT_OUTPUT_DELIMITER); } Throwable cause = t.getCause(); if (cause == null || t == cause) { break; } t = cause; builder.append("$CAUSE$"); builder.append(JUNIT_OUTPUT_DELIMITER); } return builder.toString(); }
Example 8
Source File: ForkedPinpointPluginTest.java From pinpoint with Apache License 2.0 | 5 votes |
private String failureToString(Failure failure) { StringBuilder builder = new StringBuilder(); builder.append(failure.getTestHeader()); builder.append(JUNIT_OUTPUT_DELIMITER); Throwable t = failure.getException(); while (true) { builder.append(t.getClass().getName()); builder.append(JUNIT_OUTPUT_DELIMITER); builder.append(t.getMessage()); builder.append(JUNIT_OUTPUT_DELIMITER); for (StackTraceElement e : failure.getException().getStackTrace()) { builder.append(e.getClassName()); builder.append(','); builder.append(e.getMethodName()); builder.append(','); builder.append(e.getFileName()); builder.append(','); builder.append(e.getLineNumber()); builder.append(JUNIT_OUTPUT_DELIMITER); } Throwable cause = t.getCause(); if (cause == null || t == cause) { break; } t = cause; builder.append("$CAUSE$"); builder.append(JUNIT_OUTPUT_DELIMITER); } return builder.toString(); }
Example 9
Source File: TestEngine.java From restcommander with Apache License 2.0 | 5 votes |
@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: IsFailure.java From spectrum with MIT License | 5 votes |
@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 11
Source File: JUnit4TestRunner.java From quickperf with Apache License 2.0 | 5 votes |
private List<Throwable> convertJUnit4FailuresToThrowables(List<Failure> jUnit4Failures) { List<Throwable> throwables = new ArrayList<>(); for (Failure failure : jUnit4Failures) { Throwable throwable = failure.getException(); throwables.add(throwable); } return throwables; }
Example 12
Source File: JUnitRunListener.java From ratis with Apache License 2.0 | 5 votes |
private static Throwable getTimeoutException(Failure failure) { if (failure == null) { return null; } final Throwable throwable = failure.getException(); if (throwable.getClass() != TIMEOUT_EXCEPTION.getClass()) { return null; } final String message = throwable.getMessage(); if (message == null || !message.startsWith(TIMEOUT_EXCEPTION_PREFIX)) { return null; } return throwable; }
Example 13
Source File: JUnitRunListener.java From incubator-ratis with Apache License 2.0 | 5 votes |
private static Throwable getTimeoutException(Failure failure) { if (failure == null) { return null; } final Throwable throwable = failure.getException(); if (throwable.getClass() != TIMEOUT_EXCEPTION.getClass()) { return null; } final String message = throwable.getMessage(); if (message == null || !message.startsWith(TIMEOUT_EXCEPTION_PREFIX)) { return null; } return throwable; }
Example 14
Source File: AtsJunitTestListener.java From ats-framework with Apache License 2.0 | 5 votes |
/** * * @see org.junit.runner.notification.RunListener#testFailure(org.junit.runner.notification.Failure) */ @Override public void testFailure( Failure failure ) throws Exception { if (!ActiveDbAppender.isAttached) { return; } if (log.isDebugEnabled()) { log.debug("testFailure(): Test failed: " + failure.toString() + "| Description: " + failure.getDescription()); } try { lastStartedMethodIsFailing = true; //TODO check if failure.getDescription() represents several methods. This might be in case of exception // in @BeforeClass // if this is an assertion error, we need to log it Throwable failureException = failure.getException(); if (failureException instanceof AssertionError) { logger.error(MSG__TEST_FAILED_ASSERTION_ERROR, failureException); //.getMessage() ); } else { logger.error(MSG__TEST_FAILED, failureException); } //open a performance test scenario and test case logger.endTestcase(TestCaseResult.FAILED); sendTestEndEventToAgents(); } catch (Exception e) { try { logger.fatal("UNEXPECTED EXCEPTION IN AutoLogTestListener@onTestFailure", e); } catch (Exception e1) { e1.printStackTrace(); } } finally { super.testFailure(failure); } }
Example 15
Source File: TextResultRenderer.java From JPPF with Apache License 2.0 | 5 votes |
/** * Render the specified failure. * @param failure the failure to render. */ private void renderFailure(final Failure failure) { renderDescription(failure.getDescription(), "Failure"); if (failure.getException() != null) { incIndentation(); final String s = ExceptionUtils.getStackTrace(failure.getException()); body.append(indent(s, getIndentation())).append("\n"); decIndentation(); } }
Example 16
Source File: NettyClientInteropServlet.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
private void doGetHelper(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); PrintWriter writer = resp.getWriter(); writer.println("Test invoked at: "); writer.println(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss Z") .format(Calendar.getInstance().getTime())); Result result = new JUnitCore().run(Tester.class); if (result.wasSuccessful()) { resp.setStatus(200); writer.println( String.format( "PASS! Tests ran %d, tests ignored %d", result.getRunCount(), result.getIgnoreCount())); } else { resp.setStatus(500); writer.println( String.format( "FAILED! Tests ran %d, tests failed %d, tests ignored %d", result.getRunCount(), result.getFailureCount(), result.getIgnoreCount())); for (Failure failure : result.getFailures()) { writer.println("================================"); writer.println(failure.getTestHeader()); Throwable thrown = failure.getException(); StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); thrown.printStackTrace(printWriter); writer.println(stringWriter); } } }
Example 17
Source File: ITJUnitUtils.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
@Override public void testFailure(Failure failure) { SCBFailure scbFailure = new SCBFailure(failure.getDescription(), failure.getException()); failures.add(scbFailure); System.out.println(scbFailure.toString()); }