我很难让nUnit TestCaseSource属性在nUnit 2.6.4.14350中正确工作。
当通过VS2010运行单元测试时,它只是说测试被忽略了,而没有提供任何关于原因的额外信息。Create测试在测试结果查看器上显示为灰色。
在我的例子中,被测试的类是TestCaseSource本身。这就是我得到的:
public class TestClass
{
static TestClass()
{
PopulateIds();
}
public IEnumerable<object> CreateTestCases
{
get
{
return _ids.Select(id => new TestCaseData(id).SetName("createTest_" + id));
}
}
private static string[] _ids;
private static void PopulateIds()
{
_ids = new string[] { "id123", // ... }
}
[TestFixtureSetUp]
public void Init()
{
// this completes successfully
}
[Test, TestCaseSource("CreateTestCases")]
public void Create(string Id)
{
// breakpoint here is never hit as test is ignored
}
}线索:
[TestFixtureSetUp]之前)。[TestCaseSource(typeof(TestClass), ...)]不会改变任何事情。public TestClass()不会改变任何事情。public IEnumberable<TestCaseSource> CreateTestCases或public IEnumberable CreateTestCases不会改变任何事情。[TestCaseSource(typeof(TestClass), "asdfasdf")]失败。我见过this question,但还是没能让它开始工作。我还试着让它像在this answer中一样工作,结果是一样的。我想我一定是在做一些很愚蠢的事,但我太生气了,看不出是什么。有人能指点我吗?
发布于 2015-06-16 14:10:47
您的问题很可能是由于您的测试运行程序不支持TestCaseSource属性而引起的,特别是如果它被报告为Create。NUnit重命名使用TestCaseSource的测试,以便将参数名称组合到测试的名称中。对于您的测试,它应该报告为createTest_id123 (测试的名称+参数的值)。
使用NUnit GUI检查您的程序集,看看在从那里运行时测试是否按预期的方式工作。如果他们这样做了,那么这将确认您的TestRunner是问题所在。使用VS2012+,您可以使用通过Nuget安装的NUnit测试适配器来运行测试。其他加载项,如Resharper (取决于版本)应该支持该属性,但我不确定哪些版本将与VS2010一起工作。
https://stackoverflow.com/questions/30869031
复制相似问题