private void showAssertInfo ( IAssert < ? > assertCommand , AssertionError ex , boolean failedTest ) { ITestResult testResult = Reporter . getCurrentTestResult ( ) ; // Checks whether the soft assert was called in a TestNG test run or else within a Java application. String methodName = "main" ; if ( testResult != null ) { methodName = testResult . getMethod ( ) . getMethodName ( ) ; } StringBuilder sb = new StringBuilder ( ) ; sb . append ( "Soft Assert " ) ; if ( assertCommand . getMessage ( ) != null && ! assertCommand . getMessage ( ) . trim ( ) . isEmpty ( ) ) { sb . append ( "[" ) . append ( assertCommand . getMessage ( ) ) . append ( "] " ) ; } if ( failedTest ) { sb . append ( "failed in " ) ; } else { sb . append ( "passed in " ) ; } sb . append ( methodName ) . append ( "()\n" ) ; if ( failedTest ) { sb . append ( ExceptionUtils . getStackTrace ( ex ) ) ; } Reporter . log ( sb . toString ( ) , true ) ; }
Shows a message in Reporter based on the assert result and also includes the stacktrace for failed assert .