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

后端 未结 10 686
梦毁少年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:57

    I say use the constructor unless you need TestContext.

    1. If you can keep things simple, why not. A constructor is simpler than a magical attribute.
    2. You can use readonly which is a big thing in test initialization where you want to prepare stuff for the tests that they're not supposed to change (ideally the stuff you prepare would be immutable too).

提交回复
热议问题