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

后端 未结 10 674
梦毁少年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条回答
  •  萌比男神i
    2020-12-02 15:54

    I prefer to use the [TestInitialize] method to perform instantiation of the object being tested and it's parameters. I only perform work in the constructor if it is necessary to instantiate a testing base class (which is usually where I create or refresh repositories, etc). This helps me keep the test framework code and test code separate logically and physically.

提交回复
热议问题