When do I use the TestFixtureSetUp attribute instead of a default constructor?

前端 未结 9 1103
旧巷少年郎
旧巷少年郎 2021-01-30 15:59

The NUnit documentation doesn\'t tell me when to use a method with a TestFixtureSetup and when to do the setup in the constructor.

public class MyTe         


        
9条回答
  •  生来不讨喜
    2021-01-30 16:12

    Why would you need to use a constructor in your test classes?

    I use [SetUp] and [TearDown] marked methods for code to be executed before and after each test, and similarly [TestFixtureSetUp] and [TestFixtureTearDown] marked methods for code to be executed only once before and after all test in the fixture have been run.

    I guess you could probably substitute the [TestFixtureSetUp] for a constructor (although I haven't tried), but this only seems to break from the clear convention that the marked methods provide.

提交回复
热议问题