[英]When TestNG suite is executed, older versions of test class are being used
[英]Test is not executed if return type is not void in a TestNG Class
仅在将类文件作为 TestNG 执行时 执行测试方法之前。 在结果中跳过、失败或通过测试用例计数 = 0。 在整个脚本执行过程中没有错误或异常。 但是当我更改返回到 void 类时成功执行。 任何人都可以请提出这个原因吗?
您可以在 testng 套件文件中使用 allow-return-values 将 testng 视为测试。 通常对于测试,返回值没有意义,它们应该是独立的单位——即使你添加了返回类型,如果允许返回值为真,Testng 也会简单地忽略它们。
这是一个示例,显示了这一点。
import org.testng.Reporter;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestClassSample {
@BeforeMethod
public void beforeMethod() {
Reporter.log("beforeMethod() executed", true);
}
@Test
public String testMethod() {
Reporter.log("testMethod() executed", true);
return null;
}
}
这里是对应的套件xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="46765400_Suite" verbose="2" allow-return-values="true">
<test name="46765400_test">
<classes>
<class name="com.rationaleemotions.stackoverflow.qn46765400.TestClassSample"/>
</classes>
</test>
</suite>
这是执行输出
...
... TestNG 6.12 by Cédric Beust (cedric@beust.com)
...
beforeMethod() executed
testMethod() executed
PASSED: testMethod
===============================================
46765400_test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
46765400_Suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.