I first posted this on StackOverflow
http://stackoverflow.com/questions/8609516/best-way-to-write-testng-tests-where-one-test-depends-on-the-output-of-another,
where Cedric suggested I try here and post some code too.
Summary
I have several webservices that all return a status code and a XML
payload. For each one, I need need to test and verify
1. That they return the expected status code for the given input
(test called testWebserviceStatus in code, but now referred to as
TestA)
2. If the status code is correct, then I would like to verify 1 or
more properties of the payload. Every property is independent, so I
would like to have each property verification run as a separate test
(test called testWebserviceProperties in code, but now referred to as
TestB).
Other requrements
1. The ability to add/remove the list of webservices to test and
add/remove the list of properties to verify for each service without
updating the test code.
2. If Test A fails, then its associated TestB should be skipped
3. The test report should clearly show the success failure of each
TestA/TestB test along with the webservice/property that was being
tested
TestA takes its from an DataProvider fed by an XML file.
TestB requires the output (XML payload) of TestB, so I initially made
it depend on it via DependsOnGroups. However, since that meant that
any failure of TestA meant that no TestB would run, I resorted to
using a higher priority for TestA.
Question:
Given these requirements, is this the recommended TestNG way to
structure this test, or is there a better way.
I created a greatly simplified version of what I am trying to do at
https://github.com/Ulrich-Palha/TestNG-Question