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


当前回答

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

其他回答

单元测试

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

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

功能测试

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.

AFAIK,单元测试不是功能测试。让我用一个小例子来解释。您希望测试电子邮件web应用程序的登录功能是否正常工作,就像用户一样。为此,您的功能测试应该如下所示。

1- existing email, wrong password -> login page should show error "wrong password"!
2- non-existing email, any password -> login page should show error "no such email".
3- existing email, right password -> user should be taken to his inbox page.
4- no @symbol in email, right password -> login page should say "errors in form, please fix them!" 

我们的功能测试是否应该检查我们是否可以使用无效输入登录?如。电子邮件没有@符号,用户名有多个点(只有一个点是允许的),.com出现在@之前等等?一般来说,没有!这种测试会进入单元测试。

您可以检查单元测试中是否拒绝了无效输入,如下面的测试所示。

class LoginInputsValidator
  method validate_inputs_values(email, password)
    1-If email is not like string.string@myapp.com, then throw error.
    2-If email contains abusive words, then throw error.
    3-If password is less than 10 chars, throw error.

注意,功能测试4实际上做的是单元测试1所做的。有时,由于不同的原因,功能测试可能会重复单元测试所完成的部分(而不是全部)测试。在我们的示例中,我们使用功能测试4来检查在输入无效输入时是否出现特定的错误消息。我们不想测试是否所有坏的输入都被拒绝了。这就是单元测试的工作。

测试类型

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测试) (安卓系统测试)

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

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

基本上:

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

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

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

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

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

单元测试: 单元测试特别用于逐个组件地测试产品,特别是在产品开发过程中。 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.