简体   繁体   English

单元测试适配器抛出异常:System.NullReferenceException:Object 引用未设置为 object 的实例

[英]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.

相关问题 类型'System.NullReferenceException'的异常:对象引用未设置为对象的实例 - An exception of type 'System.NullReferenceException' : Object reference not set to an instance of an object 为什么在运行单元测试时出现以下错误:“ System.NullReferenceException:对象引用未设置为对象的实例。” - Why am I getting the following error: “System.NullReferenceException: Object reference not set to an instance of an object.” when I run a Unit Test? 会话{“对象引用未设置为对象的实例。”} System.Exception {System.NullReferenceException} - session {“Object reference not set to an instance of an object.”} System.Exception {System.NullReferenceException} System.NullReferenceException - 未将对象引用设置为对象的实例 - System.NullReferenceException – Object reference not set to an instance of an object Foreach System.NullReferenceException:未将对象引用设置为对象的实例 - Foreach System.NullReferenceException: Object reference not set to an instance of an object System.NullReferenceException:对象引用未设置为对象的实例 - System.NullReferenceException: Object reference not set to an instance of an object 错误:System.NullReferenceException:对象引用未设置为对象的实例 - Error :System.NullReferenceException: Object reference not set to an instance of an object Xamarin android System.NullReferenceException:未将对象引用设置为对象的实例 - Xamarin android System.NullReferenceException: Object reference not set to an instance of an object System.NullReferenceException:未将对象引用设置为对象的实例 - System.NullReferenceException: Object reference not set to an instance of an object System.NullReferenceException:对象引用未设置为对象的实例 - System.NullReferenceException: Object reference not set to an instance of an object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM