单元测试
2016-03-25 10:16
253 查看
首先,先上概念,以下出自wiki:
In computer programming, unit testing is a software testing method by which individual units of source code, sets of one or more computer program
modules together with associated control data, usage procedures,and operating procedures, are tested to determine whether they are fit for use. Intuitively, one can view a unit as the smallest testable part of an application. In procedural programming, a unit
could be an entire module, but it is more commonly an individual function or procedure. In object-oriented programming, a unit is often an entire interface, such as a class, but could be an individual method.Unit tests are short code fragments created by programmers
or occasionally by white box testers during the development process.It forms the basis for component testing.
看了几篇文章我觉得这是最正统的一个对单元测试的定义,单元测试是白盒测试的一种,它是对代码的最小功能单元进行测试。
而什么是最小单元,我觉得这个其实可以对照单一职责。在过程化编程中,一个单元就是单个程序、函数、过程等;对于面向对象编程,最小单元就是方法,包括基类(超类)、抽象类、或者派生类(子类)中的方法。
这么做的好处在于写单元测试,可以使我们尽早地发现错误,同时提高了代码的质量。
A unit test is code that exercises a specific portion of your codebase in a particular context. Typically, each unit test sends a specific
input to a method and verifies that the method returns the expected value, or takes the expected action. Unit tests prove that the code you are testing does in fact do what you expect it to do.
我们在单元测试调用方法时,会输入一些参数,并对调用方法后产生的结果有一个预期值。
其实我们的单元测试就是在测试我们写出的代码和我们预期它达到的效果一不一致。
今天大概写点概念,明天会增加Junit用法
In computer programming, unit testing is a software testing method by which individual units of source code, sets of one or more computer program
modules together with associated control data, usage procedures,and operating procedures, are tested to determine whether they are fit for use. Intuitively, one can view a unit as the smallest testable part of an application. In procedural programming, a unit
could be an entire module, but it is more commonly an individual function or procedure. In object-oriented programming, a unit is often an entire interface, such as a class, but could be an individual method.Unit tests are short code fragments created by programmers
or occasionally by white box testers during the development process.It forms the basis for component testing.
看了几篇文章我觉得这是最正统的一个对单元测试的定义,单元测试是白盒测试的一种,它是对代码的最小功能单元进行测试。
而什么是最小单元,我觉得这个其实可以对照单一职责。在过程化编程中,一个单元就是单个程序、函数、过程等;对于面向对象编程,最小单元就是方法,包括基类(超类)、抽象类、或者派生类(子类)中的方法。
这么做的好处在于写单元测试,可以使我们尽早地发现错误,同时提高了代码的质量。
A unit test is code that exercises a specific portion of your codebase in a particular context. Typically, each unit test sends a specific
input to a method and verifies that the method returns the expected value, or takes the expected action. Unit tests prove that the code you are testing does in fact do what you expect it to do.
我们在单元测试调用方法时,会输入一些参数,并对调用方法后产生的结果有一个预期值。
其实我们的单元测试就是在测试我们写出的代码和我们预期它达到的效果一不一致。
今天大概写点概念,明天会增加Junit用法
相关文章推荐
- DBGridEh-dghMultiSortMarking
- RenderBody,RenderPage和RenderSection
- 使用Topshelf部署Windows服务
- android:使用Messenger进行进程间通信(一)
- sql优化方式
- 断言--NSAssert
- Linux字符设备驱动详解
- Oracle学习(二)
- 关于双向链表的审计 audit
- servletcontext的使用总结
- mybatis常用jdbcType数据类型
- JS过滤空格,回车符。
- mmap和shm共享内存的区别和联系
- C# 类构造函数赋值里属性与字段赋值注意项
- HTML、css、JavaScript 代码分离
- 最新版本gcc5.3安装详解
- 全站HTTPS能带来怎样的优势?HTTPS原理是什么、如何加密?
- 3月份.xyz域名总量10强:新网榜尾 十强地位不稳
- bs cs 区别
- 关于Qt中常用的延时方法--自我总结