Another small post on TestNG custom logger. I have a TestNG test suite that runs for hours doing through integration tests. Now at the end of the test run I can see testNG reports and see what failed and what passed, however I get no response during the test run as to if all tests are failing due to some configuration issue or its a normal test run. This is happening due to a fact that its basically only 1 test with DataProvider providing different test parameters. If you have separate tests then yes you will get messages for each test.
Anyhow I wanted a custom TestNG logger which logs a message that I understand at the end of each test and here is a way to do so.
Extend TestListenerAdapter class and override a few methods.
Add a custom Listener to your testng xml config:
Anyhow I wanted a custom TestNG logger which logs a message that I understand at the end of each test and here is a way to do so.
Extend TestListenerAdapter class and override a few methods.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.clearqa.utils; | |
import org.testng.ITestResult; | |
import org.testng.TestListenerAdapter; | |
public class TestNgCustomLogger extends TestListenerAdapter{ | |
@Override | |
public void onTestFailure(ITestResult tr) { | |
logToStdOut(tr, "FAILED"); | |
} | |
@Override | |
public void onTestSkipped(ITestResult tr) { | |
logToStdOut(tr, "SKIPPED"); | |
} | |
@Override | |
public void onTestSuccess(ITestResult tr) { | |
logToStdOut(tr, "PASS"); | |
} | |
private void logToStdOut(ITestResult tr, String result){ | |
Object[] parameters = tr.getParameters(); | |
System.out.println("Test with parameters " + result); | |
for(Object o : parameters) { | |
System.out.println("\t -" + o.toString()); | |
} | |
} | |
} |
Add a custom Listener to your testng xml config:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > | |
<suite name="REST api Integration Tests" verbose="1" data-provider-thread-count="10"> | |
<listeners> | |
<listener class-name="com.clearqa.utils.TestNgCustomLogger" /> | |
</listeners> | |
<test name="Rest API - Json schema validation Tests" > | |
<classes> | |
<class name="com.clearqa.restapi.test.RestApiITCase" /> | |
</classes> | |
</test> | |
</suite> |
and wola I get the much needed indication on the std out:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mvn test-compile failsafe:integration-test | |
[INFO] Scanning for projects... | |
[INFO] | |
[INFO] ------------------------------------------------------------------------ | |
[INFO] Building XXXX Webapp 1.0.5-SNAPSHOT | |
[INFO] ------------------------------------------------------------------------ | |
[INFO] | |
....blah blah blah.... | |
....blah blah blah.... | |
[INFO] Failsafe report directory: XXXX\target\failsafe-reports | |
------------------------------------------------------- | |
T E S T S | |
------------------------------------------------------- | |
Running TestSuite | |
Test with parameters PASS | |
-XXXX | |
Test with parameters FAILED | |
-YYYY | |
... | |
... |
No comments:
Post a Comment