Nar*_*esh 15 nunit unit-testing
我有一个测试,我不需要在运行测试之前运行该SetUp方法(归因于[SetUp]).我需要SetUp为其他测试运行该方法.
是否有可以使用的不同属性或基于非属性的方法来实现此目的?
Mik*_*ill 24
您还可以添加类别并检查设置中的类别列表:
public const string SKIP_SETUP = "SkipSetup";
[SetUp]
public void Setup(){
if (!CheckForSkipSetup()){
// Do Setup stuff
}
}
private static bool CheckForSkipSetup() {
ArrayList categories = TestContext.CurrentContext.Test
.Properties["_CATEGORIES"] as ArrayList;
bool skipSetup = categories != null && categories.Contains( SKIP_SETUP );
return skipSetup ;
}
[Test]
[Category(SKIP_SETUP)]
public void SomeTest(){
// your test code
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7830 次 |
| 最近记录: |