I think this means a log4j Appender output to TestNG Listener and a proper log4j configuration in the src/test/resources directory of my Maven project. Is that correct?
It seems quite easy to write, but is there anything I can import through Maven?
Copy the following classes:
public class TestNGReportAppender extends AppenderSkeleton {
@Override
protected void append (final LoggingEvent event) {
Reporter.log(eventToString(event));
}
private String eventToString(final LoggingEvent event) {
final StringBuilder result = new StringBuilder(layout.format(event));
if(layout.ignoresThrowable()) {
final String[] s = event.getThrowableStrRep();
if ( s != null) {
for (final String value: s) {
result.append(value).append(Layout.LINE_SEP);
}
}
}
return result.toString();
}
@Override
public void close() {
}
@Override
public boolean requiresLayout() {
return true;
}
}
and configure it as a console appe nder. For example. Like this:
log4j.appender.testNG=some.package.TestNGReportAppender
log4j.appender.testNG.layout=org.apache.log4j. EnhancedPatternLayout
log4j.appender.testNG.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L-%m%
Me Use log4j and hope that the log messages that usually end in my logging tool appear in the test report created by TestNG during my unit test.
I think this means a log4j Appender output To the TestNG Listener and an appropriate log4j configuration in the src/test/resources directory of my Maven project. Is that correct?
It seems quite easy to write, but is there anything I can import through Maven?
I had the same problem and eventually wrote an appender myself. It is actually very simple:
Copy the following class :
public class TestNGReportAppender extends AppenderSkeleton {
@Override
protected void append(final LoggingEvent event) {
Reporter. log(eventToString(event));
}
private String eventToString(final LoggingEvent event) {
final StringBuilder result = new StringBuilder(layout.format(event));< br />
if(layout.ignoresThrowable()) {
final String[] s = event.getThrowableStrRep();
if (s != null) {
for ( final String value: s) {
result.append(value).append(Layout.LINE_SEP);
}
}
}
return result.toString() ;
}
@Override
public void close() {
}
@Override
public boolean requiresLayout() {
return true;
}
}
and configure it as a console appender. For example. Like this:
log4j.appender.testNG=som e.package.TestNGReportAppender
log4j.appender.testNG.layout=org.apache.log4j.EnhancedPatternLayout
log4j.appender.testNG.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1} :%L-%m%