问题描述
我需要将输出结果(失败或成功)进入log4j输出.
Assert.assertTrue(availresponse);
有什么方法可以将testng控制台输出添加到log4j.log文件中?
推荐答案
终于找到了在log4j中记录Assert error的最简单方法
在catch block中应该是Throwable,如果是Exception,则不起作用.
try { Assert.assertTrue(hotel.getAmenitiesList().size() < 0, "Hotel Amenities Available!"); } catch (Throwable e) { e.printStackTrace(); logger.error("FAILED: testRoomAmenities ", e); Assert.fail();
当此实现不称为FAIL时.它将表明场景为PASSED.因此,您应该使用Assert.fail()使那是FAILED
其他推荐答案
我找到了一种简单,简单,完美的方法,可将TESTNG输出记录到log4j.log文件中.但这不能是log4j(通过或失败)中的最终报告详细信息.
implements ITestListener
然后添加未完成的方法
public void onTestSuccess(ITestResult result) { logger.info(result); } public void onTestFailure(ITestResult result) { logger.info(result); }
您可以在所需的方法中添加log4j logger.享受!
其他推荐答案
如果需要,可以使用if .. else构造进行记录.
if(null != availresponse) { //log success message } else { //log failure message }
另一种方法是编写实现TestListenerAdapter的自定义类.您可以看到完整的示例代码在这里..
问题描述
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?
推荐答案
Finally found the easiest way to log the Assert error in log4j
In catch block it should be Throwable, if it is Exception that will not work.
try { Assert.assertTrue(hotel.getAmenitiesList().size() < 0, "Hotel Amenities Available!"); } catch (Throwable e) { e.printStackTrace(); logger.error("FAILED: testRoomAmenities ", e); Assert.fail();
When this implement that will not invoke as FAIL. It will show that scenario is PASSED. Therefore you should use Assert.fail() to make that is FAILED
其他推荐答案
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).
implements ITestListener
Then add unimplemented methods
public void onTestSuccess(ITestResult result) { logger.info(result); } public void onTestFailure(ITestResult result) { logger.info(result); }
You can add log4j logger in the methods you need. Enjoy!
其他推荐答案
If you need that, you could use if .. else construct to do the logging.
if(null != availresponse) { //log success message } else { //log failure message }
Another way is to write a custom class implementing TestListenerAdapter. You can see full example code here.