问题描述
我正在从事一个大型项目,即使有成百上千的自动化测试和 100% 的代码覆盖率,我们也会遇到大量错误.我们得到的大约 95% 的错误都是 NullReferenceExceptions.
I'm working on a large project where, even with 10s of 1000s of automated tests and 100% code coverage, we're getting a ridiculous number of errors. About 95% of errors we get are NullReferenceExceptions.
有没有办法在编译时强制执行空检查?
Is there any way to enforce null-checking at compile time?
除此之外,有没有什么方法可以在单元测试中自动强制执行空检查,而不必自己为空情况编写测试?
Barring that, is there any way to automagically enforce null-checking in unit tests without having to write the tests for null cases myself?
推荐答案
您应该查看 代码合同.静态检查器仅适用于高端 VS 版本,但这基本上是您所追求的.
You should look into Code Contracts. The static checker is only available for the higher-end VS editions, but that's basically what you're after.
网上有很多资源,<plug> 你还可以阅读 C# 2nd edition in Depth 中关于代码契约的章节的预发布版本 - 免费下载第 15 章.</plug>(这一章相对于最新和最伟大的代码契约版本来说有点过时,但没什么大不了的.)
There are plenty of resources online, and <plug> you can also read a prerelease version of the chapter on Code Contracts from the 2nd edition of C# in Depth - download chapter 15 for free. </plug> (The chapter is slightly out of date with respect to the latest and greatest build of Code Contracts, but nothing huge.)
这篇关于如何强制执行空检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)