【发布时间】:2015-02-20 08:08:53
【问题描述】:
我有以下类,它是一个 TestFixture,它有一个测试和一个产生我的 TestCases 的 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");
}
}
}
}
}
}
当我运行我的测试时,我收到以下错误,很遗憾这不是很有帮助!
System.NullReferenceException : Object reference not set to an instance of an object.
关于我可能做错了什么有什么建议吗?
【问题讨论】:
-
你能看一下异常堆栈跟踪和失败的行号吗?它通常更有帮助。