C#使用TestCaseSource进行NUnit将导致空指针

C#使用TestCaseSource进行NUnit将导致空指针,c#,nunit,C#,Nunit,我有下面的类,它是一个TestFixture,它有一个测试和一个生成我的测试用例的TestCaseSource。我的测试用例实际上包含实际结果和预期结果,它们被包装在一个名为TestCaseEntity的对象中 namespace SomeNamespace { [TestFixture] public class MyTest { static Client client; static List<string> userId

我有下面的类,它是一个TestFixture,它有一个测试和一个生成我的测试用例的TestCaseSource。我的测试用例实际上包含实际结果和预期结果,它们被包装在一个名为TestCaseEntity的对象中

namespace SomeNamespace
{
    [TestFixture]
    public class MyTest
    {
        static Client client;
        static List<string> userIds = new List<string>();

        [TestFixtureSetUp]
        public void Init()
        {
            // Set up a client
            client = new Client("server address"); // a HTTP client

            // populate a List of userIds from a local text test file
            userIds.Add(GetAllIdsFromTxtFile());
        }

        [Test, TestCaseSource(typeof(MyTestCaseEntityFactory), "MyTestCases")]
        public void CheckExpectations(TestCaseEntity testCaseEntity)
        {
            if (!testCaseEntity.IsIdentical)
            {
                Log.Error("Log some shit");
                Assert.Fail("fail assertions");
            }
        }

        public class MyTestCaseEntityFactory
        {
            public static IEnumerable<TestCaseEntity> MyTestCases
            {
                get
                {
                    foreach (string id in userIds)
                    {
                        // use the client and get the results, construct the new TestCaseEntity(...) and return;
                        yield return new TestCaseEntity("actualValue", "expectedValue resulting from the server call");
                    }
                }
            }
        }
    }
}

关于我可能做错了什么,有什么建议吗?

您可以查看
所有SalesdeDealId
,但您似乎没有将其包含在代码示例中。这可能是代码中的
NullRefException

很抱歉,这是一个输入错误,但这绝对不是问题所在。我可以看到init方法正在成功执行!allSalesDEDealIds方法在init方法之前就被调用了,因此您需要执行所有的逻辑来获取该方法中的ID,即userIds.Add(GetAllIdsFromTxtFile());必须在allSalesDEDealIds方法内调用。您可以查看异常堆栈跟踪和失败的行号吗?它通常更有用。
System.NullReferenceException : Object reference not set to an instance of an object.