如何运行集成测试?
在我们的项目中,我们有大量的单元测试。它们有助于使项目得到充分的测试。
除此之外,我们还有一组测试,它们是单元测试,但依赖于某种外部资源。我们将其称为外部测试。例如,他们有时可以访问网络服务。
虽然单元测试很容易运行,但集成测试有时无法通过:例如,由于超时错误。此外,这些测试可能需要花费太多时间来运行。
目前,我们保留集成/外部单元测试只是为了在开发相应功能时运行它们。
对于简单的单元测试,我们使用 TeamCity 进行持续集成。
如何运行集成单元测试以及何时运行它们?
In our project, we have a plenty of unit tests. They help to keep project rather well-tested.
Besides them, we have a set of tests which are unit tests but depends on some kind of external resource. We call them external tests. For example, they can sometimes access web-services.
While unit tests are easy to run, the integrational tests couldn't pass sometimes: for example, due to timeout error. Also, these tests can take too much time to run.
Currently, we keep integration/external unit tests just to run them when developing corresponding functionality.
For plain unit tests, we use TeamCity for continuous integration.
How do you run the integration unit tests and when do you run them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在我们的项目中,我们有单独的常规/普通单元测试套件和单独的集成测试套件。造成这种情况的原因有两个:
我们使用 TeamCity 作为主要的持续集成服务器,使用 Maven 作为构建系统。我们使用以下算法来运行测试:
mvn clean install
在 TeamCity 代理上每次提交后自动运行单元测试我们触发集成测试执行的方式是将 TeamCity 的integration.tests 任务配置为依赖于“main”continous.build 任务,请参阅此处了解详细信息:http://confluence.jetbrains.net/display/TCD4/Dependency+Triggers
我们仅通过以下方式运行集成测试(不包括单元测试):
“src/it/java”以保持集成
测试,
In our project we have separate suite for regular/plain unit tests and separate suite for integration tests. The are two reasons for that:
We use TeamCity as our main Continuous Integration server and Maven as build system. We use the following algorithm to run the tests:
mvn clean install
The way we trigger integration tests execution is by configuring TeamCity's integration.tests task to be dependent on "main" continous.build task, see here for details: http://confluence.jetbrains.net/display/TCD4/Dependencies+Triggers
We run only integration tests (excluding unit tests) by:
"src/it/java" to keep integration
tests,
我们使用 Maven2:maven-surefire-plugin 来运行单元测试(在测试阶段),使用 maven-failsafe-plugin 来运行集成测试(集成测试阶段)。
默认情况下,所有测试都会在项目构建时运行,但是可以使用配置文件关闭集成测试。
在许多情况下,集成测试是模块的一部分,在某些情况下,还有专门的模块只进行集成测试。
其中一个团队还使用 Fitnesse 进行验收测试。这些测试也在专用模块中。
我们使用 Hudson 进行 CI。
We're using Maven2: maven-surefire-plugin to run unit tests (in the test phase) and maven-failsafe-plugin for integration tests (integration-test phase).
By default, all tests run when the project is built, however integration tests can be turned off using profiles.
In many cases integration tests are the part of the module, n some cases there are also dedicated modules which only do integration tests.
One of the teams also uses Fitnesse for acceptance testing. These tests are also in dedicated modules.
We're using Hudson for CI.
我们在一个巨大的套件中运行所有测试。运行需要7分钟。
我们的集成测试创建模拟服务器。它们永远不会超时——除非测试要求服务器超时。
所以我们有以下几种事情。 (代码示例是 Python)
这有一些限制——它总是为每个测试分叉客户端模拟服务器。有时这还可以,但有时启动和停止的次数太多了。
我们还有以下类型的东西
为了支持此测试,我们有许多用于各种集成测试的模型服务器。
We run all the tests in one huge suite. It takes 7 minutes to run.
Our integration tests create mock servers. They never time out -- except when the test requires the server to time out.
So we have the following kinds of things. (The code sample is Python)
This has some limitations -- it's always forking the client mock server for each test. Sometimes that's okay, and sometimes that's too much starting and stopping.
We also have the following kinds of things
To support this testing, we have a number of mocked-up servers for various kinds of integration tests.
我们使用Jenkins自动运行我们的测试。
请注意单元测试和集成测试之间的区别。谈论“集成单元测试”令人困惑
Maven 提供了区分单元测试和集成测试的良好支持 -
故障保护和Surefire 插件。
来自 Apache Maven 项目:
Failsafe 插件旨在运行集成测试,而 Surefire 插件旨在运行单元测试。
(参见:http://maven.apache.org/surefire/maven-failsafe-插件/)
您需要在 pom.xml 中配置这些插件,
然后仅使用
mvn test
- 运行单元测试或mvn verify
运行集成测试。单元测试应每 15 分钟定期运行一次。
集成测试,通常需要很长时间,并且应该每 24 小时运行一次。
希望对其他人有帮助。
We use Jenkins to run our tests automatically.
Be careful of differencing between Unit and Integration - Tests. It is confusing to talk about "Integration Unit Tests"
Maven offers good support to distinguish between Unit and Integration Tests-
Failsafe & Surefire Plugin.
From Apache Maven Project:
The Failsafe Plugin is designed to run integration tests while the Surefire Plugin is designed to run unit tests.
(see: http://maven.apache.org/surefire/maven-failsafe-plugin/)
You need to configure these Plugins in your pom.xml
You then only use
mvn test
- to run unit tests ormvn verify
to run integration tests.Unit test should run periodically f.i. every 15 min.
Integration Test, normally take long, and should run f.i. every 24 hours.
Hope that helps others.