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

查看:47
本文介绍了单元测试和集成测试有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单元测试和集成测试有什么区别?

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?

推荐答案

单元测试 是由程序员编写的测试,用于验证相对较小的代码段是否正在执行预期的操作做.它们的范围很窄,它们应该易于编写和执行,它们的有效性取决于程序员认为有用的内容.这些测试旨在供程序员使用,它们对其他人没有直接用处,但是,如果他们完成自己的工作,测试人员和下游用户应该会从更少的错误中受益.

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.

实际上,集成测试"被用于各种各样的事情,从针对模拟生产环境的全面系统测试到使用未模拟的资源(如数据库或队列)的任何测试.在低端,集成测试可以是 junit 测试,其中存储库针对内存数据库执行,在高端,它可以是验证应用程序可以交换消息的系统测试.

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.

这篇关于单元测试和集成测试有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆