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


当前回答

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


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


单元测试应该是这样的:当我调用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.


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


其他回答

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

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


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


单元测试应该是这样的:当我调用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文件保存测试的默认配置。 你可以参观一下。

单元测试: 单元测试特别用于逐个组件地测试产品,特别是在产品开发过程中。 Junit和Nunit类型的工具还将帮助您按照单元测试产品。 **与其在整合之后解决问题,不如在开发早期就解决问题。

功能测试: 就测试而言,主要有两种类型的测试 1.功能测试 2.非功能性测试。

Non-Functional Test is a test where a Tester will test that The product will perform all those quality attributes that customer doesn't mention but those quality attributes should be there. Like:-Performance,Usability,Security,Load,Stress etc. but in the Functional Test:- The customer is already present with his requirements and those are properly documented,The testers task is to Cross check that whether the Application Functionality is performing according to the Proposed System or not. For that purpose Tester should test for the Implemented functionality with the proposed System.

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

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