MSTest每次启动时可以运行特定的方法吗?
问题
有没有办法让一个方法在通过 MSTest 运行测试程序集时始终运行?
与 [TestInitialize] 和 [ClassInitialize] 属性的工作方式类似,但适用于整个程序集。 我不想向每个测试类的 [ClassInitialize] 方法添加代码。
推理
我的一些测试与数据库交互。 他们删除对生产数据库非常有害的数据和其他内容。 只有一个配置文件告诉我的单元测试项目针对非生产数据库运行。
如果有一种在启动时运行的方法会说“好吧,数据库名称不是‘生产’”,我会感觉更好。
Ideas
Log4Net 使用程序集属性来配置自身。
using log4net.Config;
[assembly: XmlConfigurator()]
也许我可以做一些类似的事情?
[assembly: CheckDatabaseNameNot("production")]
Question
Is there a way to have a method that will always run anytime that test assembly is run through MSTest?
Similar to how the [TestInitialize] and [ClassInitialize] attributes work, but for the entire assembly. I do not want to have to add code to every test class's [ClassInitialize] method.
Reasoning
Some of my tests interact with the database. They delete data and other things that would be very harmful to a production database. There is only a configuration file that tells my unit test project to run against the non-production database.
I would feel better if there was a method that would run on startup that would say "Okay Database name is not 'production'"
Ideas
Log4Net uses an assembly attribute to configure itself.
using log4net.Config;
[assembly: XmlConfigurator()]
Perhaps I can do something simliar?
[assembly: CheckDatabaseNameNot("production")]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试过[AssemblyInitialize]吗?
Have you tried [AssemblyInitialize]?