单元测试和功能测试之间的区别是什么?单元测试也可以测试函数吗?
当前回答
单元测试告诉开发人员代码的工作是正确的;功能测试告诉开发人员代码正在做正确的事情。
你可以在单元测试与功能测试中阅读更多内容
单元测试和功能测试在现实生活中的类比可以描述如下:
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服务等依赖项交互。
单元测试告诉开发人员代码的工作是正确的;功能测试告诉开发人员代码正在做正确的事情。
你可以在单元测试与功能测试中阅读更多内容
单元测试和功能测试在现实生活中的类比可以描述如下:
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.
总结一下,
单元测试是从程序员的角度编写的。它们用于确保类的特定方法(或单元)执行一组特定的任务。
功能测试是从用户的角度编写的。它们确保系统按照用户的期望运行。
测试类型
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测试) (安卓系统测试)
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来检查在输入无效输入时是否出现特定的错误消息。我们不想测试是否所有坏的输入都被拒绝了。这就是单元测试的工作。
单元测试通常由开发人员完成。这样做的目的是确保他们的代码正常工作。一般的经验法则是使用单元测试覆盖代码中的所有路径。
功能测试:这是一个很好的参考。功能测试说明
推荐文章
- 如何使用“测试”包打印Go测试?
- 如何在IntelliJ中为整个项目配置“缩短命令行”方法
- toBe(true) vs toBeTruthy() vs toBeTrue()
- 使用Mockito测试抽象类
- 什么时候应该使用Debug.Assert()?
- 使用Moq模拟单元测试的异步方法
- 你的项目没有引用“. net framework,Version=v4.6.2”框架。在“TargetFrameworks”中添加对“.NETFramework,Version=v4.6.2”的引用
- 使用Moq模拟扩展方法
- 从控制台停止一个Android应用程序
- 基于输入参数模拟python函数
- 用于单元测试的NUnit vs. Visual Studio 2008测试项目
- 在使用信号时,你不能在'原子'块的末尾执行查询,但只能在单元测试期间执行
- .NET核心单元测试-模拟IOptions<T>
- 使Android模拟器运行得更快
- 如何使用JUnit来测试异步进程