我如何强制执行空检查? [英] How do I enforce null checking?

查看:151
本文介绍了我如何强制执行空检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个大项目中,即使有自动化测试和100%code覆盖1000个10秒,我们得到错误的荒谬的数字。错误的约95%,我们得到的是NullReferenceException异常。

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?

推荐答案

您应该看看 code合同的。静态检查仅适用于高端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.

有丰富的资源网络,和<即插即用GT; 你也可以阅读从第2上code合同章的$ P $租赁前的版本免费 下载第15章 - 的C#在深度版。 < /插头> (该章是略显过时相对于code合同的最新和最伟大的版本,但没有什么巨大的)

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.)

这篇关于我如何强制执行空检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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