是否有可能在c#中进行单元测试,构造函数,如果是,如果不是为什么Plz响应。 [英] Is It possible to unit test, constructor in c#, if yes how if not why Plz response .

查看:76
本文介绍了是否有可能在c#中进行单元测试,构造函数,如果是,如果不是为什么Plz响应。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有







是否可以在c#中进行单元测试,构造函数,如果是的话如果不是为什么Plz回应。



谢谢

Dear All



Is It possible to unit test, constructor in c#, if yes how if not why Plz response .

Thanks

推荐答案

是..它的可能单元测试和构造函数无所事事规则 [ ^ ]
Yes.. Its possible Unit testing and the "constructors do nothing" rule[^]


是的,通过实例化对象然后断言对象的字段被正确初始化来执行此操作。您还可以断言在构造函数期间没有抛出异常。如果需要,您可以通过反射检查私人字段。



在您的情况下,这取决于您要在单元测试中检查的内容...
Yes, you do this by instantiating the object and then asserting the fields of the object are initialized properly. You can also assert that no exception was thrown during the constructor. You can check private fields through reflection if you need to.

In your case it depends on what you want to check in the unit test...


这篇关于是否有可能在c#中进行单元测试,构造函数,如果是,如果不是为什么Plz响应。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆