Search in sources :

Example 1 with ResultPrinter

use of junit.textui.ResultPrinter in project junit4 by junit-team.

the class TextFeedbackTest method testError.

public void testError() {
    String expected = expected(new String[] { ".E", "Time: 0", "Errors here", "", "FAILURES!!!", "Tests run: 1,  Failures: 0,  Errors: 1", "" });
    ResultPrinter printer = new TestResultPrinter(new PrintStream(output)) {

        @Override
        public void printErrors(TestResult result) {
            getWriter().println("Errors here");
        }
    };
    runner.setPrinter(printer);
    TestSuite suite = new TestSuite();
    suite.addTest(new TestCase() {

        @Override
        public void runTest() throws Exception {
            throw new Exception();
        }
    });
    runner.doRun(suite);
    assertEquals(expected, output.toString());
}
Also used : PrintStream(java.io.PrintStream) TestSuite(junit.framework.TestSuite) ResultPrinter(junit.textui.ResultPrinter) TestCase(junit.framework.TestCase) TestResult(junit.framework.TestResult)

Example 2 with ResultPrinter

use of junit.textui.ResultPrinter in project junit4 by junit-team.

the class TextRunnerSingleMethodTest method testSingle.

public void testSingle() throws Exception {
    TestRunner t = new TestRunner();
    t.setPrinter(new ResultPrinter(new PrintStream(new ByteArrayOutputStream())));
    String[] args = { "-m", "junit.tests.runner.TextRunnerSingleMethodTest$InvocationTest.testWasInvoked" };
    fgWasInvoked = false;
    t.start(args);
    assertTrue(fgWasInvoked);
}
Also used : PrintStream(java.io.PrintStream) ResultPrinter(junit.textui.ResultPrinter) TestRunner(junit.textui.TestRunner) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with ResultPrinter

use of junit.textui.ResultPrinter in project junit4 by junit-team.

the class ForwardCompatibilityPrintingTest method testErrorAdapted.

public void testErrorAdapted() {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    TestRunner runner = new TestRunner(new TestResultPrinter(new PrintStream(output)));
    String expected = expected(new String[] { ".E", "Time: 0", "Errors here", "", "FAILURES!!!", "Tests run: 1,  Failures: 0,  Errors: 1", "" });
    ResultPrinter printer = new TestResultPrinter(new PrintStream(output)) {

        @Override
        public void printErrors(TestResult result) {
            getWriter().println("Errors here");
        }
    };
    runner.setPrinter(printer);
    runner.doRun(new JUnit4TestAdapter(ATest.class));
    assertEquals(expected, output.toString());
}
Also used : PrintStream(java.io.PrintStream) ResultPrinter(junit.textui.ResultPrinter) TestRunner(junit.textui.TestRunner) TestResult(junit.framework.TestResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JUnit4TestAdapter(junit.framework.JUnit4TestAdapter)

Example 4 with ResultPrinter

use of junit.textui.ResultPrinter in project junit4 by junit-team.

the class ForwardCompatibilityPrintingTest method testError.

public void testError() {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    TestRunner runner = new TestRunner(new TestResultPrinter(new PrintStream(output)));
    String expected = expected(new String[] { ".E", "Time: 0", "Errors here", "", "FAILURES!!!", "Tests run: 1,  Failures: 0,  Errors: 1", "" });
    ResultPrinter printer = new TestResultPrinter(new PrintStream(output)) {

        @Override
        public void printErrors(TestResult result) {
            getWriter().println("Errors here");
        }
    };
    runner.setPrinter(printer);
    TestSuite suite = new TestSuite();
    suite.addTest(new TestCase() {

        @Override
        public void runTest() throws Exception {
            throw new Exception();
        }
    });
    runner.doRun(suite);
    assertEquals(expected, output.toString());
}
Also used : PrintStream(java.io.PrintStream) TestSuite(junit.framework.TestSuite) ResultPrinter(junit.textui.ResultPrinter) TestCase(junit.framework.TestCase) TestRunner(junit.textui.TestRunner) TestResult(junit.framework.TestResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 5 with ResultPrinter

use of junit.textui.ResultPrinter in project junit4 by junit-team.

the class TextFeedbackTest method testFailure.

public void testFailure() {
    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)) {

        @Override
        public void printFailures(TestResult result) {
            getWriter().println("Failures here");
        }
    };
    runner.setPrinter(printer);
    TestSuite suite = new TestSuite();
    suite.addTest(new TestCase() {

        @Override
        public void runTest() {
            throw new AssertionFailedError();
        }
    });
    runner.doRun(suite);
    assertEquals(expected, output.toString());
}
Also used : PrintStream(java.io.PrintStream) TestSuite(junit.framework.TestSuite) ResultPrinter(junit.textui.ResultPrinter) TestCase(junit.framework.TestCase) TestResult(junit.framework.TestResult) AssertionFailedError(junit.framework.AssertionFailedError)

Aggregations

PrintStream (java.io.PrintStream)5 ResultPrinter (junit.textui.ResultPrinter)5 TestResult (junit.framework.TestResult)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 TestCase (junit.framework.TestCase)3 TestSuite (junit.framework.TestSuite)3 TestRunner (junit.textui.TestRunner)3 AssertionFailedError (junit.framework.AssertionFailedError)1 JUnit4TestAdapter (junit.framework.JUnit4TestAdapter)1