MsTest - executing method before each test in an assembly

后端 未结 5 1484
青春惊慌失措
青春惊慌失措 2021-02-06 21:45

Is it possible to run specific method before each test in an assembly?

I know about TestInitialize attribute but this attribute has \"class scope\". If it\'

5条回答
  •  太阳男子
    2021-02-06 22:23

    I am not sure that this feature is possible in MsTest out of box like in other test frameworks (e.g. MbUnit).

    If I have to use MsTest, then I am solving this by defining abstract class TestBase with [TestInitialize] attribute and every test which needs this behaviour derives from this base class. In your case, every test class in your assembly must inherit from this base...

    And there is probably another solution, you can make your custom test attribute - but I have not tried this yet... :)

提交回复
热议问题