本文介绍了Nunit测试System.NullReferenceException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是NUnit测试的新手,我收到以下错误: 消息:System.NullReferenceException:对象引用未设置为对象的实例 我的测试结果如下
[测试] public void TestCheckConsumer() {服务检查= new 服务(); CheckStockResponse response = check.CheckStock( new Credentials(), new CheckInput()); Assert.AreEqual(Status.Registered,response); }是需要的模拟,或者我可以在测试设置中创建样本数据
解决方案可以调试NUnit测试 - 试试看! Visual Nunit有时候有些笨拙,但有耐心并再次尝试,它可以实现。 找出崩溃实际发生的位置非常重要。已经在Services()的构造函数中?或者在其CheckStock函数中? 请注意,此处使用的.exe.config文件默认为NUnit文件,即当您需要访问配置设置时,事情变得有点困难。
I'm new to NUnit testing and i received the following error: Message: System.NullReferenceException : Object reference not set to an instance of an object my test is a follows
[Test] public void TestCheckConsumer() { Services check = new Services(); CheckStockResponse response = check.CheckStock(new Credentials(), new CheckInput()); Assert.AreEqual(Status.Registered, response); }is a mock required or can i just create sample data in the test setup
解决方案 NUnit Tests can be debugged - try that! Visual Nunit is sometimes a bit mulish, but with patience and trying it again, it can be accomplished. It is important to find out where the crash actually happens. Already in the constructor of Services()? Or in its CheckStock function? Note that the .exe.config file used here is that of NUnit by default, i.e. when you need to access configuartion settings, things get a little harder to do them right.更多推荐
Nunit测试System.NullReferenceException
发布评论