I need to get output result (FAIL or SUCCESS) into log4j output.
Assert.assertTrue(availresponse);
Is there any way to add TestNG console output into log4j.log file?
I need to get output result (FAIL or SUCCESS) into log4j output.
Assert.assertTrue(availresponse);
Is there any way to add TestNG console output into log4j.log file?
I found a simple, easy and perfect way to log TestNG output into log4j.log file. But this can't be log Final Report Details into log4j (PASS or FAIL).
Then add unimplemented methods
You can add log4j logger in the methods you need. Enjoy!
Wrap the assert with a logger e.g.
However this is a bit limited in terms of information. What I usually do is:
I know it's a bit of a hassle, testing for the condition twice but it does allow you to tweak the output level of the logger and add any other information you think would be useful e.g. the variables which were used to determine the contents of availresponse.
Alternatively you could try getting the console output to appear in your log file in which case you'll need to add something like:
to your log4j properties file.
You can find
test-output
folder in your project PATH.index.html
will show the Test output of Success or Fail.If the
testMethod()
is Success, there will no any output result shows inindex.html
file. You can add Success message by usingReporter.log()
If
testmethod()
fail, automatically it will prints output in file.NOTE :
java.lang.AssertionError
is an error that thrown to indicate that an assertion has failed.If anyone know how TestNG inserting that error to the report, comment below.
If you need that, you could use
if .. else
construct to do the logging.Another way is to write a custom class implementing
TestListenerAdapter
. You can see full example code here.Finally found the easiest way to log the
Assert error
inlog4j
In
catch block
it should beThrowable
, if it isException
that will not work.When this implement that will not invoke as
FAIL
. It will show that scenario isPASSED
. Therefore you should useAssert.fail()
to make that isFAILED