CTRL4TestNG

Logging for the current TestNG test result

Download .zip Download .tar.gz View on GitHub

CTRL4TestNG: Current Test Result Logger for TestNG

Build Status Coverage Status Maven Central

Join the chat at https://gitter.im/mfulton26/ctrl4testng

The Current Test Result Logger for TestNG (CTRL4TestNG) provides an SLF4J Logger that can be used from any TestNG method tied to an ITestResult (i.e. methods annotated as Test, BeforeClass, AfterClass, etc.). Each separate method will have its own unique Logger and can be used with TestNG's parallel testing support making it clear which logs came from which method even when data-driven by means of DataProviders and/or Factories.

Usage

Simply change your SLF4J Logger initializations in your code to use CTRL4TestNG's LOGGER constant instead of SLF4J's LoggerFactory. See CTRL4TestNGExampleTest for an example including example output.

As CTRL4TestNG's LOGGER constant is a public static you can also use it through static import.

Logger Category Format

CTRL4TestNG forwards logging requests to a unique Logger for each Before/After/Test TestNG method. Each method's logger is named using the following format:

[method-name]{[method-parameters]} on [class-instance-string] in [xml-suite-name]

The class-instance-string is either the test class's toString() return value, if overriden, or the test class's simple name.

Example Output

The following example output is from running CTRL4TestNGExampleTest with TestNG.

11:11:09.335 [main] INFO  log{} on DataDrivenClass{message=message 1} in ctrl4testng - message 1
11:11:09.339 [main] INFO  log{} on DataDrivenClass{message=message 2} in ctrl4testng - message 2
11:11:09.342 [main] INFO  info{message 1} on DataDrivenMethod{} in ctrl4testng - message 1
11:11:09.342 [main] INFO  info{message 2} on DataDrivenMethod{} in ctrl4testng - message 2
11:11:09.344 [main] ERROR error{} on Simple{} in ctrl4testng - this is an error log message
11:11:09.346 [main] INFO  info{} on Simple{} in ctrl4testng - this is an informational log message
11:11:09.347 [main] WARN  warn{} on Simple{} in ctrl4testng - this is a warning log message
11:11:09.349 [main] INFO  tearDownMethod{} on Simple{} in ctrl4testng - supports before and after methods too