FileDocCategorySizeDatePackage
SummaryJUnitResultFormatter.javaAPI DocApache Ant 1.705094Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.taskdefs.optional.junit

SummaryJUnitResultFormatter

public class SummaryJUnitResultFormatter extends Object implements JUnitTaskMirror.SummaryJUnitResultFormatterMirror, JUnitResultFormatter
Prints short summary output of the test to Ant's logging system.

Fields Summary
private NumberFormat
nf
Formatter for timings.
private OutputStream
out
OutputStream to write to.
private boolean
withOutAndErr
private String
systemOutput
private String
systemError
Constructors Summary
public SummaryJUnitResultFormatter()
Empty


          
      
    
Methods Summary
public voidaddError(junit.framework.Test test, java.lang.Throwable t)
Empty

param
test not used.
param
t not used.

    
public voidaddFailure(junit.framework.Test test, java.lang.Throwable t)
Empty

param
test not used.
param
t not used.

    
public voidaddFailure(junit.framework.Test test, junit.framework.AssertionFailedError t)
Interface TestListener for JUnit > 3.4.

A Test failed.

param
test not used.
param
t not used.

        addFailure(test, (Throwable) t);
    
public voidendTest(junit.framework.Test test)
Empty

param
test not used.

    
public voidendTestSuite(JUnitTest suite)
The whole testsuite ended.

param
suite the testsuite.
throws
BuildException if there is an error.

        String newLine = System.getProperty("line.separator");
        StringBuffer sb = new StringBuffer("Tests run: ");
        sb.append(suite.runCount());
        sb.append(", Failures: ");
        sb.append(suite.failureCount());
        sb.append(", Errors: ");
        sb.append(suite.errorCount());
        sb.append(", Time elapsed: ");
        sb.append(nf.format(suite.getRunTime() / 1000.0));
        sb.append(" sec");
        sb.append(newLine);

        if (withOutAndErr) {
            if (systemOutput != null && systemOutput.length() > 0) {
                sb.append("Output:").append(newLine).append(systemOutput)
                    .append(newLine);
            }

            if (systemError != null && systemError.length() > 0) {
                sb.append("Error: ").append(newLine).append(systemError)
                    .append(newLine);
            }
        }

        try {
            out.write(sb.toString().getBytes());
            out.flush();
        } catch (IOException ioex) {
            throw new BuildException("Unable to write summary output", ioex);
        } finally {
            if (out != System.out && out != System.err) {
                try {
                    out.close();
                } catch (IOException e) {
                    // ignore
                }
            }
        }
    
public voidsetOutput(java.io.OutputStream out)
{@inheritDoc}.

        this.out = out;
    
public voidsetSystemError(java.lang.String err)
{@inheritDoc}.

        systemError = err;
    
public voidsetSystemOutput(java.lang.String out)
{@inheritDoc}.

        systemOutput = out;
    
public voidsetWithOutAndErr(boolean value)
Should the output to System.out and System.err be written to the summary.

param
value if true write System.out and System.err to the summary.

        withOutAndErr = value;
    
public voidstartTest(junit.framework.Test t)
Empty

param
t not used.

    
public voidstartTestSuite(JUnitTest suite)
The testsuite started.

param
suite the testsuite.

        String newLine = System.getProperty("line.separator");
        StringBuffer sb = new StringBuffer("Running ");
        sb.append(suite.getName());
        sb.append(newLine);

        try {
            out.write(sb.toString().getBytes());
            out.flush();
        } catch (IOException ioex) {
            throw new BuildException("Unable to write summary output", ioex);
        }