![](/img/trans.png)
[英]An exception of type 'System.NullReferenceException' : Object reference not set to an instance of an object
[英]Unit Test Adapter threw exception: System.NullReferenceException: Object reference not set to an instance of an object
我创建了一个测试项目,它有一个测试 function。
public void TestMethod1()
{
Logger.Instance.WriteLog("hello", false);
int actual = Obj.Addition(4, 5);
int expected = 9;
Assert.AreEqual(actual, expected);
}
我已经创建了这个测试方法的负载测试,但是当我尝试执行负载测试时,所有测试都失败了,它显示错误单元测试适配器抛出异常:System.NullReferenceException:Object 引用未设置为 object 的实例。
错误是在声明 Logger.Instance.WriteLog("hello", false) 时发生的; 如果不存在此语句,则负载测试执行成功。 记录器 class 只是将日志写入文本文件。
听起来你的Logger.Instance
可能是 null - 这个记录器通常需要某种初始化吗? 在使用它之前,确保你已经正确地初始化了它。
堆栈跟踪应该准确地确定NullReferenceException
被抛出的位置——也许它在Logger.WriteLog
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.