Forcing MSTest to use a single thread

前端 未结 6 773
抹茶落季
抹茶落季 2020-12-09 01:48

Given this test fixture:

[TestClass]
public class MSTestThreads
{
    [TestMethod]
    public void Test1()
    {
              


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 02:13

    I tried a bit of a different approach, because the underlying problem is that the names of the pipes are the problem. So I made a fakePipe, derived it from the one I use in the program. And named the pipe with the tests name.

    [TestClass]
    public class PipeCommunicationContractTests {
      private PipeDummy pipe;
    
      /// 
      ///Gets or sets the test context which provides
      ///information about and functionality for the current test run.
      ///
      public TestContext TestContext { get; set; }
    
      [TestInitialize]
      public void TestInitialize() {
         pipe = new PipeDummy(TestContext.TestName);
         pipe.Start();
      }
    
      [TestCleanup]
      public void TestCleanup() {
      {
         pipe.Stop();
         pipe = null;
      }
       ...
      [TestMethod]
      public void CallXxOnPipeExpectResult(){
          var result = pipe.Xx();
          Assert.AreEqual("Result",result); 
      }
    }
    

    It appears to be a bit faster, since we can run on multiple cores and threads...

提交回复
热议问题