TestInitialize vs ClassInitialize

前端 未结 1 1992
面向向阳花
面向向阳花 2020-11-30 02:34

What is the difference between TestInitialize vs ClassInitialize in MSTest? What are the pros cons of each?

I\'m under the impression that

相关标签:
1条回答
  • 2020-11-30 02:59

    Both attributes are available only for the classes (and hence tests) where they belong.

    TestInitialize runs before every test that is declared on the the same class where the attribute is declared.

    ClassInitialize runs only on the initialization of the class where the attribute is declared. In other words it won't run for every class. Just for the class that contains the ClassInitialize method.

    If you want a method that will run once before all tests or classes' initialization use the AssemblyInitialize.

    0 讨论(0)
提交回复
热议问题