获取NUnit的所选类别编程 [英] Getting nUnit selected categories programatically
问题描述
有,而执行测试编程获得选中的测试类别的方法吗?东西在
TestContext.Properties的行[_ SELECTCATEGORIES]
Is there a way of programatically getting the selected test categories while executing a test? something in the lines of TestContext.Properties["_SELECTCATEGORIES"]
基本上我已经有了测试用例从一个DB和负载测试数据我已经有了一个大量的试验项目花费很长的时间来加载。我试着去寻找其返回没什么testCaseSources如果没有选择类别的方式
basically i've got test cases which load the test data from a db and as i've got a lot of tests the project is taking a long time to load. Im trying to find a way of having the testCaseSources returning nothing if the category is not selected
推荐答案
更新时间:
有不出现成为内的 NUnit的框架的本身在NUnit测试组件识别或装载所选类别的任何直接的方法..
There does not appear to be any straightforward method for identifying or loading selected categories in an NUnit test assembly within the NUnit Framework itself..
使用反射,你也许可以扫描饰以 TestAttribute <类物业
类别
/ code>或 TestFixtureAttribute
。通过这些类别与要装入一(S)的匹配,你可以能够过滤掉哪些测试加载之前加载。
Using reflection, you could perhaps scan the property Categories
in classes decorated with TestAttribute
or TestFixtureAttribute
. By matching these categories with the one(s) you want to load, you could be able to filter out which tests to load before loading.
再有就是 TestContext.Test.Properties
键 _CATEGORIES
(在NUnit的2.5.7及更高版本):
And then there is the TestContext.Test.Properties
key _CATEGORIES
(available in NUnit 2.5.7 and later):
[Test]
[Category("Hello")]
public void TestCategory()
{
Assert.IsTrue(((ArrayList)TestContext.CurrentContext.Test.Properties["_CATEGORIES"]).Contains("Hello"));
}
一些更多的的TestContext $读C $ C>类,可以发现这里。当然,用这种方法来解决这个问题就需要您加载整个测试组件,并遍历所有测试用例在事前,这是您的方案显然是不可取的。
Some more to read on the TestContext
class can be found here. Of course, to solve the problem with this approach would require you to load the entire test assembly and loop over all test cases in beforehand, which is obviously undesirable in your scenario.
这篇关于获取NUnit的所选类别编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!