*/
private TestCaseReport writeTestReport( final String reportString )
throws MojoExecutionException
{
// Parse the report.
TestCaseReport report;
try
{
report = new TestCaseReport( Xpp3DomBuilder.build( new StringReader( reportString ) ) );
}
catch ( XmlPullParserException e )
{
// should never happen
throw new MojoExecutionException( e.getMessage(), e );
}
catch ( IOException e )
{
// should never happen
throw new MojoExecutionException( e.getMessage(), e );
}
// Get the test attributes.
final String name = report.getName();
final int numFailures = report.getFailures();
final int numErrors = report.getErrors();
final int totalProblems = numFailures + numErrors;
getLog().debug( "[MOJO] Test report of " + name );
getLog().debug( reportString );
// Get the output file name.
final File file = new File( reportPath, "TEST-" + name.replace( "::", "." ) + ".xml" );
FileWriter writer = null;
try
{
writer = new FileWriter( file );
IOUtil.copy( reportString, writer );
writer.flush();
}
catch ( IOException e )
{
throw new MojoExecutionException( "Unable to save test result report", e );
}
finally
{
IOUtil.close( writer );
}
// Pretty print the document to disk.
// final XMLWriter writer = new XMLWriter( new FileOutputStream( file ), format );
// writer.write( document );
// writer.close();
// First write the report, then fail the build if the test failed.
if ( totalProblems > 0 )
{
failures = true;
getLog().warn( "Unit test " + name + " failed." );
}
this.numTests += report.getTests();
this.numErrors += report.getErrors();
this.numFailures += report.getFailures();
return report;
}