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

前端 未结 9 1274
旧巷少年郎
旧巷少年郎 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:13

    I think I have a negative good answer - the reason to use a constructor instead of the attribute is when you have an inheritence between test classes.

    Only one method annotated with [TestFixtureSetup] will be called (on the concrete class only), but the other fixture initializers will not. In this case I'd rather put the initialization in the constructor, which has a well-defined semantics for inheritance :)

提交回复
热议问题