首页 > 解决方案 > 预计一个但发现了一个“你调用的对象是空的。”

问题描述

我为空参数检查创建了一个测试用例,但出现此错误:预期会抛出 <System.ArgumentNullException>,但发现 <System.NullReferenceException>: System.NullReferenceException 并显示消息“对象引用未设置为对象的实例。”

[Fact]
public void GivenNull_WhenMapIsCalled_ThenArgumentNullExceptionIsThrown()
{
    //Given

    Request request = null;

    //When
    Action action = () => new ConsumerServiceWrapper().IndividualsSearch(request);

    //Then
    action.ShouldThrow<ArgumentNullException>();

}

个人搜索

public List<Response> IndividualsSearch(Request request)
{
   var response = new List<Response>();
   //some code
   return response;
}

标签: c#.netunit-testingxunit

解决方案


推荐阅读