📄 junitservlet.java
字号:
} abstract static class DisplayedResultsFormatter extends ResultsFormatter { protected void displayHeader( PrintWriter writer, String testClassName, TestResult testResult, String elapsedTimeString ) { displayHeader( writer, testClassName, getFormatted( testResult.runCount(), "test" ), elapsedTimeString, testResult.wasSuccessful() ? "OK" : "Problems Occurred" ); } protected void displayResults( PrintWriter writer, TestResult testResult ) { if (!testResult.wasSuccessful()) { displayProblems( writer, "failure", testResult.failureCount(), testResult.failures() ); displayProblems( writer, "error", testResult.errorCount(), testResult.errors() ); } } protected abstract void displayHeader( PrintWriter writer, String testClassName, String testCountText, String elapsedTimeString, String resultString ); protected abstract void displayProblemTitle( PrintWriter writer, String title ); protected abstract void displayProblemDetailHeader( PrintWriter writer, int i, String testName ); protected abstract void displayProblemDetailFooter( PrintWriter writer ); protected abstract void displayProblemDetail( PrintWriter writer, String message ); private void displayProblems( PrintWriter writer, String kind, int count, Enumeration enumeration ) { if (count != 0) { displayProblemTitle( writer, getFormatted( count, kind ) ); Enumeration e = enumeration; for (int i = 1; e.hasMoreElements(); i++) { TestFailure failure = (TestFailure) e.nextElement(); displayProblemDetailHeader( writer, i, failure.failedTest().toString() ); if (failure.thrownException() instanceof AssertionFailedError) { displayProblemDetail( writer, failure.thrownException().getMessage() ); } else { displayProblemDetail( writer, BaseTestRunner.getFilteredTrace( failure.thrownException() ) ); } displayProblemDetailFooter( writer ); } } } private String getFormatted( int count, String name ) { return count + " " + name + (count == 1 ? "" : "s"); } } static class TextResultsFormatter extends DisplayedResultsFormatter { String getContentType() { return "text/plain"; } protected void displayHeader( PrintWriter writer, String testClassName, String testCountText, String elapsedTimeString, String resultString ) { writer.println( testClassName + " (" + testCountText + "): " + resultString ); } protected void displayFooter( PrintWriter writer ) { } protected void displayProblemTitle( PrintWriter writer, String title ) { writer.println(); writer.println( title + ':' ); } protected void displayProblemDetailHeader( PrintWriter writer, int i, String testName ) { writer.println( i + ". " + testName + ":" ); } protected void displayProblemDetailFooter( PrintWriter writer ) { writer.println(); } protected void displayProblemDetail( PrintWriter writer, String message ) { writer.println( message ); } } static class HTMLResultsFormatter extends DisplayedResultsFormatter { String getContentType() { return "text/html"; } protected void displayHeader( PrintWriter writer, String testClassName, String testCountText, String elapsedTimeString, String resultString ) { writer.println( "<html><head><title>Test Suite: " + testClassName + "</title>" ); writer.println( "<style type='text/css'>" ); writer.println( "<!--" ); writer.println( " td.detail { font-size:smaller; vertical-align: top }" ); writer.println( " -->" ); writer.println( "</style></head><body>" ); writer.println( "<table id='results' border='1'><tr>" ); writer.println( "<td>" + testCountText + "</td>" ); writer.println( "<td>Time: " + elapsedTimeString + "</td>" ); writer.println( "<td>" + resultString + "</td></tr>" ); } protected void displayFooter( PrintWriter writer ) { writer.println( "</table>" ); writer.println( "</body></html>" ); } protected void displayProblemTitle( PrintWriter writer, String title ) { writer.println( "<tr><td colspan=3>" + title + "</td></tr>" ); } protected void displayProblemDetailHeader( PrintWriter writer, int i, String testName ) { writer.println( "<tr><td class='detail' align='right'>" + i + "</td>" ); writer.println( "<td class='detail'>" + testName + "</td><td class='detail'>" ); } protected void displayProblemDetailFooter( PrintWriter writer ) { writer.println( "</td></tr>" ); } protected void displayProblemDetail( PrintWriter writer, String message ) { writer.println( sgmlEscape( message ) ); } } static class XMLResultsFormatter extends ResultsFormatter { String getContentType() { return "text/xml;charset=UTF-8"; } protected void displayHeader( PrintWriter writer, String testClassName, TestResult testResult, String elapsedTimeString ) { writer.println( "<?xml version='1.0' encoding='UTF-8' ?>\n" + "<testsuite name=" + asAttribute( testClassName ) + " tests=" + asAttribute( testResult.runCount() ) + " failures=" + asAttribute( testResult.failureCount() ) + " errors=" + asAttribute( testResult.errorCount() ) + " time=" + asAttribute( elapsedTimeString ) + ">" ); } private String asAttribute( int value ) { return '"' + Integer.toString( value ) + '"'; } private String asAttribute( String value ) { return '"' + sgmlEscape( value ) + '"'; } protected void displayFooter( PrintWriter writer ) { writer.println( "</testsuite>" ); } protected void displayResults( PrintWriter writer, TestResult testResult ) { displayResults( writer, "failure", testResult.failures() ); displayResults( writer, "error", testResult.errors() ); } private void displayResults( PrintWriter writer, String failureNodeName, Enumeration resultsEnumeration ) { for (Enumeration e = resultsEnumeration; e.hasMoreElements();) { TestFailure failure = (TestFailure) e.nextElement(); writer.println( " <testcase name=" + asAttribute( failure.failedTest().toString() ) + ">" ); writer.print( " <" + failureNodeName + " type=" + asAttribute( failure.thrownException().getClass().getName() ) + " message=" + asAttribute( failure.exceptionMessage() ) ); if (!displayException( failure )) { writer.println( "/>" ); } else { writer.println( ">" ); writer.print( sgmlEscape( BaseTestRunner.getFilteredTrace( failure.thrownException() ) ) ); writer.println( " </" + failureNodeName + ">" ); } writer.println( " </testcase>" ); } } private boolean displayException( TestFailure failure ) { return true; } protected String getLineBreak() { return ""; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -