单元测试和功能测试之间的区别是什么?单元测试也可以测试函数吗?


当前回答

测试类型

Unit testing - In Procedural programming unit is a procedure, in Object oriented programming unit is a class. Unit is isolated and reflects a developer perspective Functional testing - more than Unit. User perspective, which describes a feature, use case, story... Integration testing - check if all separately developed components work together. It can be other application, service, library, database, network etc. Narrow integration test - double[About] is used. The main purpose is to check if component is configured in a right way Broad integration test (End to End test, System test) - live version. The main purpose is to check if all components are configured in a right way UI testing - checks if user input triggers a correct action and the UI is changed when some actions are happened ... Non functional testing - other cases Performance testing - calculate a speed and other metrics Usability testing - UX ...

(iOS测试) (安卓系统测试)

其他回答

“功能测试”并不意味着测试代码中的函数(方法)。一般来说,这意味着您正在测试系统功能——当我在命令行上运行foo file.txt时,file.txt中的行可能会颠倒过来。相反,单个单元测试通常包含单个方法的单个情况——length(“hello”)应该返回5,length(“hi”)应该返回2。

另请参阅IBM关于单元测试和功能测试之间界限的论述。

单元测试

单元测试包括测试最小的代码单元,通常是函数或方法。单元测试主要由单元/方法/函数的开发人员完成,因为他们了解函数的核心。开发人员的主要目标是通过单元测试来覆盖代码。

它有一个限制,即某些函数不能通过单元测试进行测试。即使在成功完成所有单元测试之后;它不保证产品的正确操作。相同的函数可以在系统的少数部分中使用,而单元测试仅为一种用途而编写。

功能测试

It is a type of Black Box testing where testing will be done on the functional aspects of a product without looking into the code. Functional testing is mostly done by a dedicated Software tester. It will include positive, negative and BVA techniques using un standardized data for testing the specified functionality of product. Test coverage is conducted in an improved manner by functional tests than by unit tests. It uses application GUI for testing, so it’s easier to determine what exactly a specific part of the interface is responsible for rather to determine what a code is function responsible for.

根据ISTQB的说法,这两者没有可比性。功能测试不是集成测试。

单元测试是测试级别的一种,功能测试是测试的一种。

基本上:

一个系统(或组件)的功能是“它做什么”。这是 通常在需求规范中描述的是功能性的 规范,或者用例。

组件测试,也称为单元、模块和程序测试, 查找软件的缺陷,并验证软件的功能 (例如模块、程序、对象、类等),它们是分开的 可测试的。

根据ISTQB,组件/单元测试可以是功能性或非功能性:

组件测试可能包括功能测试和特定的非功能特征,如资源行为(例如内存泄漏)、性能或健壮性测试,以及结构测试(例如决策覆盖率)。

引用自软件测试基础- ISTQB认证

单元测试告诉开发人员代码的工作是正确的;功能测试告诉开发人员代码正在做正确的事情。

你可以在单元测试与功能测试中阅读更多内容


单元测试和功能测试在现实生活中的类比可以描述如下:

Many times the development of a system is likened to the building of a house. While this analogy isn't quite correct, we can extend it for the purposes of understanding the difference between unit and functional tests. Unit testing is analogous to a building inspector visiting a house's construction site. He is focused on the various internal systems of the house, the foundation, framing, electrical, plumbing, and so on. He ensures (tests) that the parts of the house will work correctly and safely, that is, meet the building code. Functional tests in this scenario are analogous to the homeowner visiting this same construction site. He assumes that the internal systems will behave appropriately, that the building inspector is performing his task. The homeowner is focused on what it will be like to live in this house. He is concerned with how the house looks, are the various rooms a comfortable size, does the house fit the family's needs, are the windows in a good spot to catch the morning sun. The homeowner is performing functional tests on the house. He has the user's perspective. The building inspector is performing unit tests on the house. He has the builder's perspective.


总结一下,

单元测试是从程序员的角度编写的。它们用于确保类的特定方法(或单元)执行一组特定的任务。

功能测试是从用户的角度编写的。它们确保系统按照用户的期望运行。

单元测试——测试单个单元,例如类中的方法(函数),模拟所有依赖项。

功能测试——又名集成测试,测试系统中的一部分功能。这将测试许多方法,并可能与数据库或Web服务等依赖项交互。