假设我的Foo
班级有以下内容:
readonly IService service;
public Foo(IService service)
{
if (service == null)
throw new ArgumentNullException("service");
this.service = service;
}
public void Start()
{
service.DoStuff();
}
到目前为止,我对构造函数进行了一个单元测试,我在其中传入 null 以验证是否ArgumentNullException
抛出了一个。我是否需要对我的构造函数进行第二次单元测试,在其中我传入一个有效IService
并验证该this.service
设置(这将需要一个公共访问器)?
或者我应该只依靠我的单元测试Start
来测试这个代码路径的方法吗?