对MSTest的全球测试初始化​​方法

问题描述:

快速的问题,我如何创建一个只运行一次,在解决方案中的所有测试运行之前的方法。

Quick question, how do I create a method that is run only once before all tests in the solution are run.

创建一个公共静态方法,饰有AssemblyInitialize属性。测试框架将再次调用每个测试运行此方法:

Create a public static method, decorated with the AssemblyInitialize attribute. The test framework will call this method once per test run:

[AssemblyInitialize()]
public static void MyTestInitialize(TestContext testContext)
{}

编辑:
另一个非常重要的细节:类此方法属于必须用装修[TestClass中] 。否则,初始化方法将无法运行。

Another very important detail: the class to which this method belongs must be decorated with [TestClass]. Otherwise, the initialization method will not run.