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


当前回答

单元测试

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

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

功能测试

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.

其他回答

测试类型

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关于单元测试和功能测试之间界限的论述。

单元测试测试一个独立的行为单元。行为的单位是什么?它是系统中可以独立进行单元测试的最小部分。(这个定义实际上是循环的,它根本不是一个定义,但在实践中似乎很管用,因为你可以直观地理解它。) 功能测试测试一个独立的功能部分。


行为单元非常小:虽然我绝对不喜欢这种愚蠢的“每个方法测试一个单元”的咒语,但从大小的角度来看,它是正确的。行为单元介于方法的一部分和几个方法之间。最多是一个对象,但不能超过一个。 一个功能块通常包含许多方法,并跨越多个对象,通常跨越多个体系结构层。


单元测试应该是这样的:当我调用validate_country_code()函数并将国家代码'ZZ'传递给它时,它应该返回false。 一个功能测试是:当我用国家代码ZZ填写发货表单时,我应该被重定向到一个帮助页面,该页面允许我从菜单中选择国家代码。


Unit tests are written by developers, for developers, from the developer's perspective. Functional tests may be user facing, in which case they are written by developers together with users (or maybe with the right tools and right users even by the users themselves), for users, from the user's perspective. Or they may be developer facing (e.g. when they describe some internal piece of functionality that the user doesn't care about), in which case they are written by developers, for developers, but still from the user's perspective.


在前一种情况下,功能测试还可以作为验收测试,并作为功能需求或功能规范的可执行编码,在后一种情况下,它们还可以作为集成测试。 单元测试经常更改,而功能测试在主要版本中不应该更改。


在Rails中,单元文件夹用于保存模型的测试,功能文件夹用于保存控制器的测试,集成文件夹用于保存涉及任意数量的控制器交互的测试。fixture是一种组织测试数据的方法;它们驻留在fixture文件夹中。test_helper。Rb文件保存测试的默认配置。 你可以参观一下。

我认为它是这样的:单元测试确定代码执行了您希望代码执行的操作(例如,您想要添加参数A和b,实际上是将它们相加,而不是减去它们),功能测试测试所有代码一起工作以获得正确的结果,因此您希望代码执行的操作实际上在系统中获得了正确的结果。