Including one method multiple times in a test in testng.xml to execute steps multiple times

寵の児 提交于 2020-01-15 19:12:33

问题


I want to execute a set of test methods multiple times as part of a test.
I'm using TestNG to specify my tests. The test I have specified in the testng.xml file is this:

<test>
        <classes>
            <class name="AddAppointment">
                <methods>
                    <include name="testLogin" />
                    <include name="addAppointment" />
                    <include name="checkApptForCurrentLocation" />
                    <include name="changeLocation" />
                    <include name="addAppointment" />
                    <include name="checkApptForCurrentLocation" />
                </methods>
            </class>
        </classes>
    </test>

After executing this test, I saw that the repeated methods did not get executed. It executed the test only till 'changeLocation'.Could anyone suggest any other solution or reason why this is not working?

Please note that I don't want to execute the methods multiple times with different set of data. So using dataproviders as suggested in a few posts I found online will not help me. Because I'm following a strict order
Thanks in advance!


回答1:


TestNG isn't a programming language and treating it as such will just lead to heartbreak. addAppointment and changeLocation are verbs in a programming language, not tests.

It looks like you have 3 tests: test for login, a test for a certain data combination in one (the default or starting) location, and a test for a certain data combination in another location. You glue these tests together using dependencies rather than sequencing using the methods/include construction.

In particular, I suggest that you set testLogin to be in a group with a name such as startup, and the first substantial test has a group-dependency on startup. The second substantial test has a method-dependency on the first substantial test.



来源:https://stackoverflow.com/questions/15703499/including-one-method-multiple-times-in-a-test-in-testng-xml-to-execute-steps-mul

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!