将TestNG与Groovy一起使用时,“未找到给定的测试”

我正在尝试将Test NG与Groovy一起使用。我实现了一个简单的测试类,但是每当尝试运行它时,都会出现以下错误:

No tests found for given includes: [tests.OTP.get]

tests.OTP类的外观如下:

class OTP{
    public static Logger log = LogManager.getLogger(HomePage.class.getName())
    String environment = 'qatesting'
    String number = '0769878787'
    @Test
    def get(){
//        SoapuiOTP s = new SoapuiOTP(environment,number)
//        s.getOTP()
        log.info("hello")
        Assert.assertEquals(0,System.getProperty("SOAPUI_OTP"))
        log.info System.getProperty('SOAPUI_OTP')
    }
}

我使用def get()旁边的播放按钮(IntelliJ)来运行测试,但在课堂上却遇到了相同的错误。请协助,我已经尝试使缓存无效并重新启动。我看过TestNG No tests found. Nothing was runTestNG - no tests were found,但没有帮助。

raypuppet 回答:将TestNG与Groovy一起使用时,“未找到给定的测试”

在用def注释的方法中,您需要用void替换@Test。如文档所述:

  

测试方法用@Test注释。除非您在testng.xml中将@Test设置为true,否则将忽略用allow-return-values标注的方法返回值的方法:

<test allow-return-values="true">
     
     

来源:https://testng.org/doc/documentation-main.html#test-methods

def返回类型编译为Object,而不是void,因此TestNG默认情况下会忽略此方法。

这种误解不是TestNG特有的,也可以在JUnit中完成:Running Groovy test cases with JUnit 5

本文链接:https://www.f2er.com/3168273.html

大家都在问