仅针对 NUnit 中的特定测试跳过 SetUp 方法? [英] Skip the SetUp method only for a particular test in NUnit?
本文介绍了仅针对 NUnit 中的特定测试跳过 SetUp 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个测试,我不需要在运行测试之前运行 SetUp
方法(归因于 [SetUp]
).我需要为其他测试运行 SetUp
方法.
I have a test where I do not need to run the SetUp
method (attributed with [SetUp]
) before running the test. I need the SetUp
method to be run for other tests.
是否可以使用不同的属性或非基于属性的方式来实现这一目标?
Is there a different attribute that can be used or a non-attribute-based way to achieve this?
推荐答案
您应该为该测试创建一个新类,其中只有它需要的设置(或缺少设置).
You should create a new class for that test which has only the setup (or lack of setup) that it needs.
或者,您可以将设置代码分解为所有其他测试调用的方法,但我不推荐这种方法.
Alternatively, you could unfactor the setup code into a method that all the other tests call, but I don't recommend this approach.
这篇关于仅针对 NUnit 中的特定测试跳过 SetUp 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文