Do you use TestInitialize or the test class constructor to prepare each test? and why?

后端 未结 10 689
梦毁少年i
梦毁少年i 2020-12-02 15:35

This question regards unit testing in Visual Studio using MSTest (this is important, because of MSTest\'s execution order). Both the method marked [TestInitialize] and the t

10条回答
  •  悲哀的现实
    2020-12-02 15:35

    I know I late to the party, but with async the is another reason (that does not existed when this question was ask) for [TestInitialize]. The allows you to do async operations to setup (eg. load a file) which is not possible in the constructor:

            private string approver;        
    
            [TestInitialize]
            public async Task Initialize()
            {
                approver = File.ReadAllTextAsync("approver.json");
            }
    

提交回复
热议问题