你把单元测试在同一项目或其他项目? [英] Do you put unit tests in same project or another project?

查看:131
本文介绍了你把单元测试在同一项目或其他项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你把单元测试中为了方便同一个项目或者你把它们放在一个单独的程序?

如果你把它们放在一个单独的程序像我们这样,我们结束了与一些解决方案中的额外项目。这是伟大的单元测试,同时编码,但你怎么发布应用程序,而所有这些多余的组件?


解决方案

在我看来,单元测试应该被放置在一个单独的程序从生产code。这里只是将单元测试在同一总成或部件作为生产code的几个缺点是:


  1. 单元测试获得附带生产code。随产品code的唯一的事情就是生产code。

  2. 组件将受到不必要的单元测试臃肿。

  3. 单元测试可以影响像建立自动化或连续构建过程。

我真的不知道有什么利弊。有一个额外的项目(或10)是不是一个骗局。

编辑:更多信息在建立和航运

我进一步建议任何自动生成过程产地和单元测试到不同的位置。理想情况下,如果生产code的构建,以及产品文件复制到单元测试目录下的单元测试生成过程只运行。这样做在实际的位这样的结果分开航运等。此外,它是相当微不足道的在一个特定的目录下运行在这一点上所有的测试自动化单元测试。

要总结一下,这里是位和其他文件的每日构建和测试和航运的总体思路:


  1. 生产构建运行,将文件制作成特定的生产目录。

    1. 只能建生产项目。

    2. 复制编译代码和其他文件到生产目录。

    3. 复制位和其他文件到发布候选目录,又名圣诞版本目录将是Release20081225。


  2. 如果生产生成成功,单元测试构建运行。

    1. 复制生产code,以测试目录。

    2. 构建单元测试,测试目录。

    3. 运行单元测试。


  3. 发送通知建设和单元测试结果给开发者。

  4. 当一个候选版本(如Release20081225)被接受,运输这些位。

Do you put unit tests in the same project for convenience or do you put them in a separate assembly?

If you put them in a separate assembly like we do, we end up with a number of extra projects in the solution. It's great for unit testing while coding but how do you release the application without all of these extra assemblies?

解决方案

In my opinion, unit tests should be placed in a separate assembly from production code. Here are just a few cons of placing unit tests in the same assembly or assemblies as production code are:

  1. Unit tests get shipped with production code. The only thing shipped with product code is production code.
  2. Assemblies will be unnecessarily bloated by unit tests.
  3. Unit tests can affect build processes like automated or continuous build.

I don't really know of any pros. Having an extra project (or 10) isn't a con.

Edit: More Info On Build and Shipping

I would further recommend that any automated build process place production and unit tests into different locations. Ideally, the unit test build process only runs if the production code builds, and copies the product files into the unit tests directory. Doing it this way results in the actual bits being separated for shipping, etc. Additionally, it is fairly trivial to run automated unit testing at this point on all tests in a particular directory.

To summarize, here is the general idea for a daily build and testing and shipping of bits and other files:

  1. Production build runs, placing production files into a specific "production" directory.

    1. Build production projects only.
    2. Copy compiled bits and other files into a "production" directory.
    3. Copy bits and other files into a release candidate directory, aka a Christmas release directory would be "Release20081225".

  2. If production build succeeds, unit test build runs.

    1. Copy production code to "tests" directory.
    2. Build unit tests to "tests" directory.
    3. Run unit tests.

  3. Send build notifications and unit tests results to developers.
  4. When a release candidate (like Release20081225) is accepted, ship these bits.

这篇关于你把单元测试在同一项目或其他项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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