Introduction
We have listed here needed steps for allowing test logging to Test Explorer Database
There are 2 actual steps:
- Configure the Log4j system - this way we know where to send the log messages
- Subscribe to TestNG so we will get informed when a test is starting or ending
Configure the Log4j system
ATS uses Log4j for its logging purpose.
Log4j is configured by a file called log4j.xml placed in the root of the classpath.
Here is an example of such file:
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <!-- Console appender --> <appender name="console" class="org.apache.log4j.ConsoleAppender"> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%-5p %d{HH:mm:ss} %c{2}: %m%n" /> </layout> <filter class="com.axway.ats.log.autodb.filters.NoSystemLevelEventsFilter"/> </appender> <!-- Test Explorer DB appender --> <appender name="db" class="com.axway.ats.log.appenders.ActiveDbAppender"> <param name="host" value="___Test Explorer server IP or Host name___" /> <param name="database" value="___My DB name___" /> <param name="port" value="___My DB Port___" /> <!-- Optional. The DB port to be used, 1443 if --> <param name="user" value="___My DB user name___" /> <param name="password" value="___My DB user password___" /> <param name="driver" value="mssql|jtds" /> <!-- JDBC driver to use. Optional, default value is jTDS --> <param name="chunkSize" value="50000" /> <!-- Set the chunk size when in batch mode. Only applicable to SQL Server log DB. Optional, the default one is 10000 --> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%c{2}: %m%n" /> </layout> </appender> <!-- Root logger configuration --> <root> <priority value="info" /> <!-- Enable logging into the console --> <appender-ref ref="console" /> <!-- Enable logging into the dedicated logging database --> <appender-ref ref="db" /> </root> </log4j:configuration>
You need to understand the following:
- Console appender
enables logging the test results in your console. It is useful while developing your tests as you can see right away what happens during the execution of this test. - DB appender
Enables logging of test execution status and messages into the Test Explorer database. This way you can review test results via Test Explorer UI.- host - where your database is located
- database - the name of your database
- port - the database port. Optional. If no port is specified, the default one for Ms SQL Server will be used - 1433.
- user - the database username
- password - the database user password
- driver - the JDBC driver to use for SQL Server connection (mssql or jtds (default one)). Should not be used for PostgreSQL.
- chunkSize - the chunk size when in batch mode. Note that this is only applicable for SQL Server log DB
- <root> node
- enable (attach) or disable the declared appenders.
- sets the priority level which defines how verbose the logging will be.
The possible options are trace, debug, info, warn, error, fatal where trace is really verbose and each next is less.
Subscribe to TestNG test execution events
You need to attach our TestNG event listener to TestNG, so we get informed when some important event has happened.
These are events telling us when a test is starting or ending. We use this information to automatically start and end RUN, SUITE and TESTCASE in the Test Explorer DB.
There are a few ways to attach this listener. In most cases, the recommended one is to have one parent class of all your test classes. If we assume this class is called BaseTest, then here is all needed to do a subscription.
import com.axway.ats.harness.testng.AtsTestngListener; @Listeners ( { AtsTestngListener.class } ) public class BaseTest { }
Supported TestNG Version
ATS currently recommends using TestNG version 6.10. Some newer versions have known issue when logging from @Before/After Method/Suite/etc annotated methods. Due to changes in TestNG listeners behavior, currently 7.x versions are not supported and DB logging will not work at all.
Deprecated TestNG listeners
Older TestNG listeners ( com.axway.ats.harness.testng.AtsTestngSuiteListener
and com.axway.ats.harness.testng.AtsTestngTestListener
) were deprecated and are removed in future versions after 4.0.6.
Now running your test, in the very beginning you will see in the console:
*** ATS *** 2019-12-21 12:34:56.789 INFO [QueueLoggerThread-Thread-1] logqueue.DbEventRequestProcessor: Started a new RUN in Test Explorer's database with id: 12
This tells us ATS was able to attach to the TestNG listener system and then it also created a new RUN in the database.
Now you can go to the Test Explorer UI and see the test result.
Back to parent page
Go to Table of Contents