码迷,mamicode.com
首页 > 其他好文 > 详细

为什么你需要测试某个字段为空的场景

时间:2018-03-17 18:48:15      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:字段   this   and   属性   erro   pos   form   put   tom   

在 “Null References: The Billion Dollar Mistake” 中,Tony Hoare,null 的发明者,曾经说到:

I call it my billion-dollar mistake. At that time, I was designing the first comprehensive type system for references in an object-oriented language. My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn‘t resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.

我称之为我十亿美元的错误。当时,我在为一个面向对象语言设计第一个综合性的面向引用的类型系统。我的目标是通过编译器的自动检查来保证所有引用的使用都应该是绝对安全的。不过我未能抵抗住引入一个空引用的诱惑,仅仅是因为它是这么的容易实现。这引发了无数错误、漏洞和系统崩溃,在之后的四十多年中造成了数十亿美元的苦痛和伤害。

在有空值的语言中,变量总是这两种状态之一:空值和非空值。

空值的问题在于当你尝试像一个非空值那样使用一个空值,会出现某种形式的错误。因为空和非空的属性是无处不在的,非常容易出现这类错误。

所以,如果你在测试的时候不去测试判空的问题,那么你可能最多漏测了50%的场景

为什么你需要测试某个字段为空的场景

标签:字段   this   and   属性   erro   pos   form   put   tom   

原文地址:https://www.cnblogs.com/nbkhic/p/8591710.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!