private String createReportContent ( String suiteName , List < TestResult > results , ReportTemplates templates ) throws IOException { final StringBuilder reportDetails = new StringBuilder ( ) ; for ( TestResult result : results ) { Properties detailProps = new Properties ( ) ; detailProps . put ( "test.class" , result . getClassName ( ) ) ; detailProps . put ( "test.name" , StringEscapeUtils . escapeXml ( result . getTestName ( ) ) ) ; detailProps . put ( "test.duration" , "0.0" ) ; if ( result . isFailed ( ) ) { detailProps . put ( "test.error.cause" , Optional . ofNullable ( result . getCause ( ) ) . map ( Object :: getClass ) . map ( Class :: getName ) . orElse ( result . getFailureType ( ) ) ) ; detailProps . put ( "test.error.msg" , StringEscapeUtils . escapeXml ( result . getErrorMessage ( ) ) ) ; detailProps . put ( "test.error.stackTrace" , Optional . ofNullable ( result . getCause ( ) ) . map ( cause -> { StringWriter writer = new StringWriter ( ) ; cause . printStackTrace ( new PrintWriter ( writer ) ) ; return writer . toString ( ) ; } ) . orElse ( result . getFailureStack ( ) ) ) ; reportDetails . append ( PropertyUtils . replacePropertiesInString ( templates . getFailedTemplate ( ) , detailProps ) ) ; } else { reportDetails . append ( PropertyUtils . replacePropertiesInString ( templates . getSuccessTemplate ( ) , detailProps ) ) ; } } Properties reportProps = new Properties ( ) ; reportProps . put ( "test.suite" , suiteName ) ; reportProps . put ( "test.cnt" , Integer . toString ( results . size ( ) ) ) ; reportProps . put ( "test.skipped.cnt" , Long . toString ( results . stream ( ) . filter ( TestResult :: isSkipped ) . count ( ) ) ) ; reportProps . put ( "test.failed.cnt" , Long . toString ( results . stream ( ) . filter ( TestResult :: isFailed ) . count ( ) ) ) ; reportProps . put ( "test.success.cnt" , Long . toString ( results . stream ( ) . filter ( TestResult :: isSuccess ) . count ( ) ) ) ; reportProps . put ( "test.error.cnt" , "0" ) ; reportProps . put ( "test.duration" , "0.0" ) ; reportProps . put ( "tests" , reportDetails . toString ( ) ) ; return PropertyUtils . replacePropertiesInString ( templates . getReportTemplate ( ) , reportProps ) ; }
Create report file for test class .