Run UnitTest a few times - don't just loop it

I have a VS UnitTest (MSTest) to cover some multi-threaded code. Without the necessary locks, the code fails the test of 15 out of 30 runs - i.e. half runs. I am fixing the code and the tests pass 30 times.

Now I want the test environment to run the N time test, and not once, to be sure that it cannot pass by good luck. There seems to be no way to do this with the attribute in the test, so I put the INSIDE loop on the test to run the body of the test code N times.

I delete the corrections to the code (locks, etc.) and run the test (which loops N times) - and it skips it. I run it again (cycle N times), and it fails ... I returned to where I started - it still fails only in half the cases (even if it performs N cycles through the test body with each test).

What I really want is not a loop inside the test, but actually the test environment loads the test, runs the test, unloads the test, etc. N times (as I did manually). How to do it? (Why is there not only a test attribute for this - for example, [TestRepeatCount=5] ?)

0
unit-testing mstest
source share
1 answer

What you really need is a Load Test . Add a unit test and configure how it will work.

You can set the number of general tests, the number of simultaneous tests etc

+1
source share

All Articles