From: Kent B. <kb...@us...> - 2002-04-12 21:36:17
|
Update of /cvsroot/junit/junit/junit/tests/runner In directory usw-pr-cvs1:/tmp/cvs-serv7250/junit/tests/runner Modified Files: TextFeedbackTest.java Log Message: Cleaned up ResultPrinter Index: TextFeedbackTest.java =================================================================== RCS file: /cvsroot/junit/junit/junit/tests/runner/TextFeedbackTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- TextFeedbackTest.java 9 Apr 2002 19:09:17 -0000 1.2 +++ TextFeedbackTest.java 12 Apr 2002 21:36:14 -0000 1.3 @@ -7,13 +7,27 @@ import junit.framework.AssertionFailedError; import junit.framework.TestCase; +import junit.framework.TestResult; import junit.framework.TestSuite; +import junit.textui.ResultPrinter; import junit.textui.TestRunner; public class TextFeedbackTest extends TestCase { OutputStream output; TestRunner runner; + class TestResultPrinter extends ResultPrinter { + TestResultPrinter(PrintStream writer) { + super(writer); + } + + /* Spoof printing time so the tests are deterministic + */ + protected String elapsedTimeAsString(long runTime) { + return "0"; + } + } + public static void main(String[] args) { TestRunner.run(TextFeedbackTest.class); } @@ -21,6 +35,7 @@ public void setUp() { output= new ByteArrayOutputStream(); runner= new TestRunner(new PrintStream(output)); + runner.setPrinter(new TestResultPrinter(new PrintStream(output))); } public void testEmptySuite() { @@ -38,23 +53,39 @@ assertEquals(expected.toString(), output.toString()); } - /* I can't think of a good way to test this until after the formatting - * has been extracted into its own object and we can spoof it - + public void testTwoTests() { + String expected= expected(new String[]{"..", "Time: 0", "", "OK (2 tests)", ""}); + TestSuite suite = new TestSuite(); + suite.addTest(new TestCase() { public void runTest() {}}); + suite.addTest(new TestCase() { public void runTest() {}}); + runner.doRun(suite); + assertEquals(expected.toString(), output.toString()); + } + public void testFailure() { - String expected= expected(new String[]{".F", "Time: 0", "", "OK (1 test)", ""}); + String expected= expected(new String[]{".F", "Time: 0", "Failures here", "", "FAILURES!!!", "Tests run: 1, Failures: 1, Errors: 0", ""}); + ResultPrinter printer= new TestResultPrinter(new PrintStream(output)) { + public void printFailures(TestResult result) { + getWriter().println("Failures here"); + } + }; + runner.setPrinter(printer); TestSuite suite = new TestSuite(); suite.addTest(new TestCase() { public void runTest() {throw new AssertionFailedError();}}); runner.doRun(suite); assertEquals(expected.toString(), output.toString()); } - */ - public void testTwoTests() { - String expected= expected(new String[]{"..", "Time: 0", "", "OK (2 tests)", ""}); + public void testError() { + String expected= expected(new String[]{".E", "Time: 0", "Errors here", "", "FAILURES!!!", "Tests run: 1, Failures: 0, Errors: 1", ""}); + ResultPrinter printer= new ResultPrinter(new PrintStream(output)) { + public void printErrors(TestResult result) { + getWriter().println("Errors here"); + } + }; + runner.setPrinter(printer); TestSuite suite = new TestSuite(); - suite.addTest(new TestCase() { public void runTest() {}}); - suite.addTest(new TestCase() { public void runTest() {}}); + suite.addTest(new TestCase() { public void runTest() throws Exception {throw new Exception();}}); runner.doRun(suite); assertEquals(expected.toString(), output.toString()); } |