下面列出了junit.framework.TestListener#junit.textui.ResultPrinter 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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)) {
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, output.toString());
}
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)) {
public void printErrors(TestResult result) {
getWriter().println("Errors here");
}
};
runner.setPrinter(printer);
TestSuite suite = new TestSuite();
suite.addTest(new TestCase() { public void runTest() throws Exception {throw new Exception();}});
runner.doRun(suite);
assertEquals(expected, output.toString());
}