开发者

Is it possible to specify the order of the tests in Visual Studio c#?

开发者 https://www.devze.com 2023-03-18 14:17 出处:网络
I have several tests in the same namespace. I did not use naming convention like Test1, Test2, ... etc for each of my unit tests. So, now when I run all tests, they don\'t run in the order I want them

I have several tests in the same namespace. I did not use naming convention like Test1, Test2, ... etc for each of my unit tests. So, now when I run all tests, they don't run in the order I want them to. Is there a way to order tests?

My tests do not fail if I don't execute them in a particular order. However, I was just wanted to execute them 开发者_运维技巧in the order they are in my test case spreadsheet.


Your tests should not be order-dependent; that breaks the concept of test noninterdependence. The lack of ability to order the tests in Visual Studio is a reflection of this concept.


The answer you are looking for is Yes. Although I agree with the principles of isolation there are scenarios where you need to test a sequence of events. In VS 2010 you can create a new 'Ordered Test' to bundle and test a set of tests sequentially.


Oh man, you are violating one of the major Unit Testing rules - "Isolation".

Test should never have any dependecy order. Do not wait for the answer, go and refactor you tests to be really independt each of other. Believe me, it is better to do now :)


Visual Studio has a built-in template for ordered tests (assuming you're using the MSTest framework). If you open the context-menu in a test-project, it is available under the "New Test" menu or directly as "Ordered Test". Never used that before, but I'm assuming that your tests get still executed in an undefined order if you are running all your tests in the solution.

0

精彩评论

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