I am having a lot of difficulty getting the nUnit TestCaseSource attribute to work correctly in nUnit 2.6.4.14350.
When running the unit tests through VS2010, it just says the tests are being ignored, without any additional information as to why. The Create
test just appears greyed out on the test results viewer.
In my case the class being tested is the TestCaseSource itself. This is what I've got:
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
}
}
Clues:
- CreateBondTestCases getter is getting hit. (before
[TestFixtureSetUp]
is called). [TestCaseSource(typeof(TestClass), ...)]
doesn't change anything.public TestClass()
doesn't change anything.public IEnumerable<TestCaseSource> CreateTestCases
orpublic IEnumerable CreateTestCases
doesn't change anything.[TestCaseSource(typeof(TestClass), "asdfasdf")]
results in Failed: System.Reflection.TargetParameterCountException : Parameter count mismatch.
I saw this question but still can't get it to work. I have also tried to get it to work as in this answer, with the same results. I guess I must be doing something pretty stupid here but I am too infuriated to see what it is. Please can somebody enlighten me?