dependentOnMethods 返回一个值
我有一个简单的场景,其中一个方法依赖于其他方法 方法。另一个方法返回一个值 - 所以该类看起来像 -
public class Temp1 {
@Test
public Integer test1() {
Reporter.log("<b>in test1</b>");
System.out.println("in test1");
return null;
}
@Test(dependsOnMethods={"test1"})
public void test2() {
Reporter.log("in test2");
System.out.println("in test2");
}
}
现在,当我执行这个时,我遇到以下异常 -
org.testng.TestNGException:
com.core.tests.Temp1.test2() is depending on nonexistent method
com.core.tests.Temp1.test1
at
org.testng.internal.MethodHelper.findMethodsNamed(MethodHelper.java:
143)
at org.testng.internal.MethodHelper.topologicalSort(MethodHelper.java:
472)
at org.testng.internal.MethodHelper.sortMethods(MethodHelper.java:
544)
at
org.testng.internal.MethodHelper.internalCollectAndOrderMethods(MethodHelper.java:
77)
at
org.testng.internal.MethodHelper.collectAndOrderMethods(MethodHelper.java:
49).........................
尽管如果方法 test1() 没有返回类型,它也可以正常工作。 有什么办法可以解决这个问题吗?
谢谢 ~T
I have a trivial scenario in which a method is dependent on other
method. And the other method returns a value -
So the class looks as -
public class Temp1 {
@Test
public Integer test1() {
Reporter.log("<b>in test1</b>");
System.out.println("in test1");
return null;
}
@Test(dependsOnMethods={"test1"})
public void test2() {
Reporter.log("in test2");
System.out.println("in test2");
}
}
Now when I execute this, I encounter following exception -
org.testng.TestNGException:
com.core.tests.Temp1.test2() is depending on nonexistent method
com.core.tests.Temp1.test1
at
org.testng.internal.MethodHelper.findMethodsNamed(MethodHelper.java:
143)
at org.testng.internal.MethodHelper.topologicalSort(MethodHelper.java:
472)
at org.testng.internal.MethodHelper.sortMethods(MethodHelper.java:
544)
at
org.testng.internal.MethodHelper.internalCollectAndOrderMethods(MethodHelper.java:
77)
at
org.testng.internal.MethodHelper.collectAndOrderMethods(MethodHelper.java:
49).........................
Though if there is no return type with method test1(), it works well.
Is there any way to get through this?
Thanks
~T
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然文档中似乎没有提到,但我也经历过用
@Test
注解的类必须有一个void
返回类型。如果您需要其他方法提供的数据,您可以尝试数据提供者机制测试NG。Although it seems not to be mentioned in the documentation, I also experienced that classes annotated with
@Test
must have avoid
return type. If you need data provided by some other method, you could try the Data Provider mechanism of TestNG.