[英]Unit Test Adapter threw exception: System.NullReferenceException: Object reference not set to an instance of an object
I have created a test project it has a test function.我创建了一个测试项目,它有一个测试 function。
public void TestMethod1()
{
Logger.Instance.WriteLog("hello", false);
int actual = Obj.Addition(4, 5);
int expected = 9;
Assert.AreEqual(actual, expected);
}
i have created load test of this testmethod but when i try to execute the load test all test got failed and it show error Unit Test Adapter threw exception: System.NullReferenceException: Object reference not set to an instance of an object.我已经创建了这个测试方法的负载测试,但是当我尝试执行负载测试时,所有测试都失败了,它显示错误单元测试适配器抛出异常:System.NullReferenceException:Object 引用未设置为 object 的实例。
the error is dur to statement Logger.Instance.WriteLog("hello", false);错误是在声明 Logger.Instance.WriteLog("hello", false) 时发生的; if this statement is not there then load test execute successfully.
如果不存在此语句,则负载测试执行成功。 logger class is just writing log in a text file.
记录器 class 只是将日志写入文本文件。
It sounds like your Logger.Instance
may be null - does this logger normally require some sort of initialization?听起来你的
Logger.Instance
可能是 null - 这个记录器通常需要某种初始化吗? Make sure you've initialized it properly before using it.在使用它之前,确保你已经正确地初始化了它。
The stack trace should pin down exactly where the NullReferenceException
is being thrown - maybe it's in Logger.WriteLog
.堆栈跟踪应该准确地确定
NullReferenceException
被抛出的位置——也许它在Logger.WriteLog
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.