开发者

dependsOnMethods which returns a value

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.inte开发者_开发知识库rnalCollectAndOrderMethods(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


Although it seems not to be mentioned in the documentation, I also experienced that classes annotated with @Test must have a void return type. If you need data provided by some other method, you could try the Data Provider mechanism of TestNG.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜