I had to start writing some unit tests using QualityTools.UnitTestFramework for the web service layer that we developed when my approach seemed wrong from the start.
It seems that unit tests should work in any order and not rely on other tests.
My initial thought was to have something similar to the following tests (a simplified example) that would work as an ordered test in the same order.
AddObject1SuccessTest
AddObject2WithSameUniqueCodeTest
(relies on the first test that created object1 first, and then waits for failure)
AddObject2SuccessTest
UpdateObject2WithSameUniqueCodeTest
(relies on the first test by creating object1 and thrid test, creating object2 first, and then fails)
UpdateObject2SuccessTest
GetObjectListTest
DeleteObjectsTest
(using the added identifiers)
However, between the tests there is no state and there is no visible way to transmit, for example, added identifiers to the deleted one.
So, does this mean that the right approach is to comprehensively test complex script interactions?
for instance
AddObjectSuccessTest
(which creates the object, gets it to validate the data, and then deletes it)
AddObjectWithSameUniqueCodeTest
(which creates object 1, then tries to create object 2 with an error, and then deletes object 1)
UpdateObjectWithSameUniqueCodeTest
(which creates object 1, then creates object 2, and then tries to update object 2 to have the same unique code as object 1 with an error, and then deletes object 1 and object 2)
Am I really wrong?
thanks
source share