问题
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