Visual Studio 2008 Unit Test: how to do it one by one?

When you do Unit Testing, is there a way to tell [TestClass ()] to execute one [TestMethod ()] alone? (Instead of Visual Studio to run multiple threads). It will be required only for one or two of my test classes.

+4
source share
3 answers

No, this is not possible in Visual Studio 2008 using the default tools.

This is possible by adding some ... interesting configuration code to the TestInit method. For example, you can use all of your test classes from the following base class.

[TestClass] public class ExecuteOneAtTimeBase { private static object s_mutex = new object(); [TestInit] public void TestInit() { Monitor.Enter(s_mutex); } [TestCleanup] public void TestCleanup() { Monitor.Exit(s_mutex); } } 

All TestMethod instances are enclosed in square brackets on calls to the TestInit and TestCleanup methods. Using the Monitor.Enter / Exit combination, you can ensure that this unit test method holds the lock for the duration of its execution. Therefore, multiple threads cannot run different tests at the same time in the same AppDomain application.

There are cases of errors when this can lead to a deadlock in the testing process. But I think this is probably a minor issue as it is not production code.

+1
source

If you are using Visual Studio 2008 Team Suite or (I think) one of the Tester releases, you can create a custom test and add all your unit test to this ordered test.

+2
source

You can debug or run any one TestMethod.

  • Place the cursor in TestMethod
  • for debugging: Ctrl-R, Ctrl-T or Test β†’ Debug β†’ Tests in the current context
  • to run: Ctrl-R, T or Test β†’ Run-> Tests in Current Context
0
source

Source: https://habr.com/ru/post/1286474/


All Articles