尽管通过@Test(testName = "sth") 设置了测试名称,但 ITestResult getTestName() 返回 null [英] ITestResult getTestName() returns null despite of set test name by @Test(testName = "sth")

查看:49
本文介绍了尽管通过@Test(testName = "sth") 设置了测试名称,但 ITestResult getTestName() 返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用注释在我的测试类中设置了测试名称:@Test(testName = "sth") 并且我需要从实现 ITestResult 的 Listener 类中获取它.方法 getTestName() 返回 null 但根据 http://testng.org/javadocs/org/testng/ITestResult.html#getTestName-- 应该返回字符串.

I set the test name in my test class using annotation: @Test(testName = "sth") and I need to get it from Listener class which implements ITestResult. Method getTestName() returns null but according to http://testng.org/javadocs/org/testng/ITestResult.html#getTestName-- should returns the string.

我做错了什么吗?是否可以从 Listener 类中获取 @Test(testName = "") 中设置的字符串?

Am I doing sth wrong? Is it possible to get the string set in @Test(testName = "") from Listener class?

推荐答案

getTestName() 在某些情况下可能会返回 null.检查 没有来自 TestNG 的回归测试 如果您想了解更多详情.根据您的需要,您可以找到另外 2 种查找测试名称的方法.

getTestName() may return null in some case. Check no regression test from TestNG if you want more details. Depending on your needs, you'll find the 2 other ways to find test names.

注意:只有 6.9.10 之后的 TestNG 版本有此行为.

Note: Only TestNG versions after 6.9.10 have this behavior.

这篇关于尽管通过@Test(testName = "sth") 设置了测试名称,但 ITestResult getTestName() 返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆