单元测试和集成测试有什么区别? [重复]

本文翻译自:What's the difference between unit tests and integration tests? [duplicate]

This question already has an answer here: 这个问题在这里已有答案:

What's the difference between unit tests and integration tests? 单元测试和集成测试有什么区别?

Are there different names for these tests? 这些测试有不同的名称吗? Like some people calling unit tests functional tests, etc? 像一些人称单元测试功能测试等?


#1楼

参考:https://stackoom.com/question/MTkv/单元测试和集成测试有什么区别-重复


#2楼

A unit test should have no dependencies on code outside the unit tested. 单元测试应该不依赖于测试单元之外的代码。 You decide what the unit is by looking for the smallest testable part. 您可以通过寻找最小的可测试部件来确定单元是什么。 Where there are dependencies they should be replaced by false objects. 如果存在依赖关系,则应将其替换为虚假对象。 Mocks, stubs .. The tests execution thread starts and ends within the smallest testable unit. 模拟,存根..测试执行线程在最小的可测试单元内开始和结束。

When false objects are replaced by real objects and tests execution thread crosses into other testable units, you have an integration test 当虚拟对象被真实对象替换并且测试执行线程跨越到其他可测试单元时,您将进行集成测试


#3楼

A unit test tests code that you have complete control over whereas an integration test tests how your code uses or "integrates" with some other code. 单元测试测试您完全控制的代码,而集成测试测试代码如何使用或“集成”其他代码。

So you would write unit tests to make sure your own libraries work as intended, and then write integration tests to make sure your code plays nicely with other code you are making use of, for instance a library. 因此,您可以编写单元测试以确保您自己的库按预期工作,然后编写集成测试以确保您的代码与您正在使用的其他代码(例如库)完美匹配。

Functional tests are related to integration tests, but refer more specifically to tests that test an entire system or application with all of the code running together, almost a super integration test. 功能测试与集成测试有关,但更具体地涉及测试整个系统或应用程序的测试,所有代码一起运行,几乎是一个超级集成测试。


#4楼

A unit test is done in (as far as possible) total isolation. 单元测试(尽可能)完全隔离。

An integration test is done when the tested object or module is working like it should be, with other bits of code. 当测试对象或模块正常工作时,使用其他代码进行集成测试。


#5楼

A unit test is a test written by the programmer to verify that a relatively small piece of code is doing what it is intended to do. 单元测试是程序员编写的一个测试,用于验证相对较小的代码片段是否正在执行预期的操作。 They are narrow in scope, they should be easy to write and execute, and their effectiveness depends on what the programmer considers to be useful. 它们的范围很窄,它们应该易于编写和执行,它们的有效性取决于程序员认为有用的东西。 The tests are intended for the use of the programmer, they are not directly useful to anybody else, though, if they do their job, testers and users downstream should benefit from seeing fewer bugs. 这些测试旨在供程序员使用,但它们并不直接对其他人有用,但是,如果他们完成工作,下游的测试人员和用户应该从看到更少的错误中受益。

Part of being a unit test is the implication that things outside the code under test are mocked or stubbed out. 作为单元测试的一部分是暗示被测试代码之外的东西被模拟或删除。 Unit tests shouldn't have dependencies on outside systems. 单元测试不应该依赖于外部系统。 They test internal consistency as opposed to proving that they play nicely with some outside system. 他们测试内部一致性,而不是证明他们与一些外部系统很好地配合。

An integration test is done to demonstrate that different pieces of the system work together. 进行集成测试以证明系统的不同部分一起工作。 Integration tests can cover whole applications, and they require much more effort to put together. 集成测试可以涵盖整个应用程序,它们需要更多的努力才能组合在一起。 They usually require resources like database instances and hardware to be allocated for them. 它们通常需要为数据库实例和硬件分配资源。 The integration tests do a more convincing job of demonstrating the system works (especially to non-programmers) than a set of unit tests can, at least to the extent the integration test environment resembles production. 集成测试在演示系统工作方面做得更有说服力(特别是对于非程序员),而不是一组单元测试,至少在集成测试环境类似于生产的程度上。

Actually "integration test" gets used for a wide variety of things, from full-on system tests against an environment made to resemble production to any test that uses a resource (like a database or queue) that isn't mocked out. 实际上,“集成测试”被用于各种各样的事情,从完全系统测试到类似生产的环境到使用未被模拟的资源(如数据库或队列)的任何测试。 At the lower end of the spectrum an integration test could be a junit test where a repository is exercised against an in-memory database, toward the upper end it could be a system test verifying applications can exchange messages. 在频谱的低端,集成测试可以是junit测试,其中存储库针对内存数据库运行,朝向上端它可以是验证应用程序可以交换消息的系统测试。


#6楼

Unit test is usually done for a single functionality implemented in Software module. 通常对软件模块中实现的单个功能进行单元测试。 The scope of testing is entirely within this SW module. 测试范围完全在此SW模块中。 Unit test never fulfils the final functional requirements. 单元测试永远不能满足最终的功能要求。 It comes under whitebox testing methodology.. 它来自白盒测试方法..

Whereas Integration test is done to ensure the different SW module implementations. 而进行集成测试以确保不同的SW模块实现。 Testing is usually carried out after module level integration is done in SW development.. This test will cover the functional requirements but not enough to ensure system validation. 测试通常在软件开发过程中完成模块级集成后进行。此测试将涵盖功能要求,但不足以确保系统验证。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值