首页 > 解决方案 > 在测试标签级别使用允许返回值

问题描述

我正在尝试allow-return-value = "true"在测试级别使用。当我运行代码时,返回类型为 non-void 的方法仍然被忽略,因为我希望调用它,因为 allow-return-value 显式设置为 true。当我在套件级别执行此操作时,这完全可以正常工作:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Retrun value True" >
    <test verbose="2" preserve-order="true" allow-return-values="true" name="TestNGExperiment">
        <classes>
            <class name="TestNGExperiment"/>
        </classes>
    </test>
</suite>

public class TestNGExperiment {

@Test(testName = "divide4by2")// the method with a return type
public int divide4by2() {
    System.out.println("divide4by2 called");
    return 4/2;
}

@Test(testName = "printHello")
public void printHello() {
    System.out.println("Hello");
}
}

实际结果:

运行的测试总数:1,通过:1,失败:0,跳过:0

根据我的预期结果:

总测试运行:2,通过:2,失败:0,跳过:0

标签: javatestng

解决方案


推荐阅读