开发者

Ordering Tests in VS 2008/2010

开发者 https://www.devze.com 2022-12-16 08:54 出处:网络
I am writing unit tests for basic CRUD functionality using VS 2010. My goal is to create new entities, read them back, update them, and then delete them.

I am writing unit tests for basic CRUD functionality using VS 2010.

My goal is to create new entities, read them back, update them, and then delete them.

One obvious approach is to have a unit test for each of those operations and run them in that order. Except that I can't directly specify the order the tests should run in.

I underst开发者_JS百科and that I can create an Ordered Test. However, after doing so and selecting "Run all tests in solution", the Ordered Test runs in addition to the individual tests. This isn't really what I'm after, especially as there is no guarantee of the order for the individual tests... some of them may "randomly" fail depending on the order they happen to be executed in.

That seems to lead to the conclusion that I would have to individually execute my Ordered Tests if I wish to use that functionality.

Alternatively I could write one big test for C+R+U+D per entity, but that isn't as atomic as I would like.

What is best-practice (without resorting to xUnit) for this type of testing?


You could create a Test List that contains only the Ordered Tests you want to run.

However, the best practice for unit testing is not to rely on test ordering at all. Ordered tests are Erratic Tests because they behave differently if executed in a different order (you already discovered that) or if executed as stand-alone tests instead of part of the ordered test suite.

Do yourself the favor and abandon the idea of ordered tests. It will only lead to more pain.

0

精彩评论

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

关注公众号