如何在 NUNIT 中有条件地运行测试?
我希望能够设置一个条件来决定某些测试是否在 NUNIT 中运行。
例如,如果全局变量 x = 1,则仅运行某个类/程序集的测试或仅运行第一个测试。
这样的事情可能吗?
人们会如何去做这件事呢?
谢谢!!
I'd like to be able to set a condition from which to decide whether certain tests run in NUNIT.
For example if a global variable x = 1 then only run the tests from a certain class/assembly or only run the first test.
Is anything like this possible?
How would one go about doing this?
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议在 NUnit 测试中使用 Categories 。这将允许您一次或同时运行它们的组。
虽然 类别 似乎是“更纯粹”的方式这样,您可以以编程方式跳过测试,就像这篇文章所要求的那样:以编程方式跳过 nunit 测试。在我看来,这种方法正是您正在寻找的。
I would recommend using Categories with your NUnit tests. This would allow you to run groups of them at a time, or all at once.
While Categories seem like the "more pure" way to do this, you could programmatically skip tests like this post asks: Programmatically skip an nunit test. It seems to me, this approach is what you're looking for though.