对MSTest的全球测试初始化方法 [英] Global test initialize method for MSTest
本文介绍了对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.
这篇关于对MSTest的全球测试初始化方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文