Quick question, how do I create a method that is run only once before all tests in the solution are run.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Create a public static method, decorated with the AssemblyInitialize attribute. The test framework will call this Setup method once per test run:
[AssemblyInitialize()]
public static void MyTestInitialize(TestContext testContext)
{}
For TearDown its:
[AssemblyCleanup]
public static void TearDown()
{}
EDIT:
Another very important detail: the class to which this method belongs must be decorated with [TestClass]
. Otherwise, the initialization method will not run.