Nunit测试System.NullReferenceException

编程入门 行业动态 更新时间:2024-10-26 08:26:19
本文介绍了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

本文发布于:2023-11-17 03:23:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608640.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:测试   Nunit   NullReferenceException   System

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!