如何运行集成测试?

发布于 2024-08-27 09:28:04 字数 294 浏览 7 评论 0原文

在我们的项目中,我们有大量的单元测试。它们有助于使项目得到充分的测试。

除此之外,我们还有一组测试,它们是单元测试,但依赖于某种外部资源。我们将其称为外部测试。例如,他们有时可以访问网络服务。

虽然单元测试很容易运行,但集成测试有时无法通过:例如,由于超时错误。此外,这些测试可能需要花费太多时间来运行。

目前,我们保留集成/外部单元测试只是为了在开发相应功能时运行它们。

对于简单的单元测试,我们使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

独行侠 2024-09-03 09:28:04

在我们的项目中,我们有单独的常规/普通单元测试套件和单独的集成测试套件。造成这种情况的原因有两个:

  1. 性能:集成测试速度要慢得多;
  2. 测试脆弱性:集成测试由于环境相关条件而更频繁地失败(给出误报)。

我们使用 TeamCity 作为主要的持续集成服务器,使用 Maven 作为构建系统。我们使用以下算法来运行测试:

  1. 我们在 Eclipse IDE 内以及每次提交之前运行单元测试。
  2. 我们使用 Maven 的 mvn clean install 在 TeamCity 代理上每次提交后自动运行单元测试
  3. 。在“主”构建完成后,我们在 TeamCity 代理上自动运行集成测试。

我们触发集成测试执行的方式是将 TeamCity 的integration.tests 任务配置为依赖于“main”continous.build 任务,请参阅此处了解详细信息:http://confluence.jetbrains.net/display/TCD4/Dependency+Triggers

我们仅通过以下方式运行集成测试(不包括单元测试):

  • 使用名为的单独目录
    “src/it/java”以保持集成
    测试,
  • 默认情况下从 maven-surefire-plugin 配置(配置/排除元素)中排除此源文件夹,
  • 使用名为“integration”的 Maven 配置文件排除常规单元测试并包含来自“src/it/java”的测试(此配置文件已配置)通过在 Integration.tests 任务中传递 -Pintegration )。

In our project we have separate suite for regular/plain unit tests and separate suite for integration tests. The are two reasons for that:

  1. performance: integration tests are much slower,
  2. test fragility: integration tests fail more often due to environment-related conditions (give false positives).

We use TeamCity as our main Continuous Integration server and Maven as build system. We use the following algorithm to run the tests:

  1. We run unit tests at within Eclipse IDE and before every commit.
  2. We run unit tests automatically after each commit on TeamCity agents using Maven's mvn clean install
  3. We run integration tests automatically on TeamCity agent after "main" build is completed.

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:

  • using separate directory named
    "src/it/java" to keep integration
    tests,
  • excluding by default this source folder from maven-surefire-plugin configuration (configuration/excludes element),
  • using Maven profile called "integration" to exclude regular unit tests and include tests from "src/it/java" (this profile is configured by passing -Pintegration in integration.tests task).
北恋 2024-09-03 09:28:04

我们使用 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.

故事灯 2024-09-03 09:28:04

我们在一个巨大的套件中运行所有测试。运行需要7分钟。

我们的集成测试创建模拟服务器。它们永远不会超时——除非测试要求服务器超时。

所以我们有以下几种事情。 (代码示例是 Python)

class SomeIntegrationTest( unittest.TestCase ):
    def setUp( self ):
        testclient.StartVendorMockServer( 18000 ) # port number
        self.connection = applicationLibrary.connect( 'localhost', 18000 )
    def test_should_do_this( self ):
        self.connection.this()
        self.assert...
    def tearDown( self ):
        testClient.KillVendorMockServer( 18000 )

这有一些限制——它总是为每个测试分叉客户端模拟服务器。有时这还可以,但有时启动和停止的次数太多了。

我们还有以下类型的东西

class SomeIntegrationTest( unittest.TestCase ):
    def setUp( self ):
        self.connection = applicationLibrary.connect( 'localhost', 18000 )
    def test_should_do_this( self ):
        self.connection.this()
        self.assert...

 if __name__ == "__main__":
     testclient.StartVendorMockServer( 18000 ) # port number
     result= unittest.TextTestRunner().run()
     testclient.KillVendorMockServer( 18000 )
     system.exit( result.failures + result.errors )

为了支持此测试,我们有许多用于各种集成测试的模型服务器。

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)

class SomeIntegrationTest( unittest.TestCase ):
    def setUp( self ):
        testclient.StartVendorMockServer( 18000 ) # port number
        self.connection = applicationLibrary.connect( 'localhost', 18000 )
    def test_should_do_this( self ):
        self.connection.this()
        self.assert...
    def tearDown( self ):
        testClient.KillVendorMockServer( 18000 )

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

class SomeIntegrationTest( unittest.TestCase ):
    def setUp( self ):
        self.connection = applicationLibrary.connect( 'localhost', 18000 )
    def test_should_do_this( self ):
        self.connection.this()
        self.assert...

 if __name__ == "__main__":
     testclient.StartVendorMockServer( 18000 ) # port number
     result= unittest.TextTestRunner().run()
     testclient.KillVendorMockServer( 18000 )
     system.exit( result.failures + result.errors )

To support this testing, we have a number of mocked-up servers for various kinds of integration tests.

假扮的天使 2024-09-03 09:28:04

我们使用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 or mvn 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文