【问题标题】:Get Annotation using TestNG 7.0.0使用 TestNG 7.0.0 获取注释
【发布时间】:2018-12-23 07:40:00
【问题描述】:

我使用 TestNG 6.11 编写了这行代码:

Annotation[] annotations =  (Annotation[]) myResult.getMethod().getMethod().getDeclaredAnnotations();

现在这段代码无法在 Maven 7.0.0-Beta1 上编译。

怎么办?

错误:

cannot find symbol [ERROR] symbol:   method getMethod() [ERROR] location: interface org.testng.ITestNGMethod

【问题讨论】:

  • 我的意思是 TestNG = 7.0.0 Beta-1,而不是 Maven。错误:找不到符号 [ERROR] 符号:方法 getMethod() [ERROR] 位置:接口 org.testng.ITestNGMethod
  • 你遇到了什么错误?
  • @TalAngel 请在您的问题中也包含该错误。

标签: java maven testng


【解决方案1】:

ITestNGMethod#getMethod()弃用,因此在以后的版本中被删除,您将不得不改用getConstructorOrMethod()

Annotation[] annotations =  (Annotation[]) iITestNGMethod.getConstructorOrMethod()
                                                         .getDeclaredAnnotations();

请参阅 TestNG 7.0.0-beta1this 文档。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多