MSTest & AppDomains

前端 未结 6 1072
囚心锁ツ
囚心锁ツ 2021-01-04 07:46

In some my project I notice that during executing unit tests under VSTS2008 its VSTestHost\'s memory consuming grows. As I have very many tests in my solution it leads to Ou

6条回答
  •  遥遥无期
    2021-01-04 08:28

    I was wrong about having separate AppDomains for each unittest.

    Here's evidence: a singleton

    public class Singleton
    {
        public static Singleton Instance = new Singleton();
    
        private Guid _token;
        private Singleton()
        {
            _token = Guid.NewGuid();
        }
    
        public Guid Token
        {
            get { return _token; }
        }
    }
    

    and two tests:

    [TestClass]
    public class UnitTest2
    {
        [TestMethod]
        public void TestMethod1()
        {
            Console.WriteLine(Singleton.Instance.Token);
        }
    }
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            Console.WriteLine(Singleton.Instance.Token);
        }
    }
    

    During executing both tests output the same guid.

提交回复
热议问题