代码依赖单元测试

发布于 2024-11-30 05:52:59 字数 274 浏览 1 评论 0原文

在我的工作场所,我们有 ac# .net 解决方案,其中包含大约 50 个项目和大约 2000 个单元测试。更改代码后,我们需要在将更改推送到构建服务器之前运行解决方案中的所有测试。运行所有测试可能需要大约 10-15 分钟。我在想 - 嘿,也许可能有一些过程可以分析我所做的所有代码更改,然后决定仅运行相关的测试方法。如果这种分析是可能的,那么计算机将只运行 15 或 100 个测试,而不是运行 2000 个测试,那么我们正在谈论的是生产力的非常好的提高和更少的麻烦。 任何人对如何实现这一点有任何想法,或者是否有此类软件可用?

In my workplace we have a c# .net solution containing about 50 projects and about 2000 unit tests. After changing code it is required that we run all tests in the solution before pushing our changes to the build server. Running all the tests can take about 10-15 minutes. I was thinking - hey, maybe there could be some process that would analyze all the code changes I made, and then decide to run only the relevant test methods. If such kind of analysis is possible, then instead of running 2000 tests the computer would run only 15 or a 100 tests, then we are talking about a very nice increase in productivity and fewer headaches.
Anyone have any ideas on how to implement this, or if such software is available?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

疧_╮線 2024-12-07 05:52:59

在多项目环境中,很难区分什么取决于什么。理想情况下:

  • 您的单元测试应该是真正的单元测试,其中 2000 个测试应该在 20 秒内运行。
  • 您运行时间较长的测试将在构建服务器上的连续构建上进行设置,因此,如果您错过了任何内容,您仍然会很快收到通知,告知您把事情搞砸了,但您个人可以承受只是一个一点点< /em> 在提交之前更有选择性地仅运行您认为可能会受到代码更改影响的测试。

It's really difficult to tell what depends on what in a multi-project environment. Ideally:

  • Your unit tests would be true unit tests, and 2000 of them should run in maybe 20 seconds.
  • Your longer-running tests would be set up on a continuous build on your build server, so you would still get notified pretty fast that you messed things up if you missed anything, but you could personally afford to be just a little more selective in running only the tests that you think you might have affected with your code changes before you commit.
你在我安 2024-12-07 05:52:59

我们的 C# 测试覆盖率工具 可以做到这一点。

  1. 它只增量地检测自此以来发生更改的文件
    最后一次测试覆盖率运行。

  2. 它可用于跟踪每个单元测试的测试覆盖率以及涉及哪些文件。当文件更改时,它将与以前的版本进行比较;如果一个方法
    以前涉及到的一些单元测试发生了变化,它标识了那些单元测试。
    您必须组织该过程以将测试运行与覆盖率数据相关联,并重新运行已识别的单元测试,但这只是脚本编写的小问题。这样做的原因是为了使测试覆盖率工具能够与任意测试框架一起运行。

您可以在构建服务器上执行此操作以节省时间。更重要的是,您可以为每个开发人员提供此功能,以便他可以在签入更改之前仅运行验证他更改的代码所需的测试。

Our C# Test Coverage Tool can do this.

  1. It incrementally instruments just the files that changed since
    the last test coverage run.

  2. It can be used to track test coverage for each unit test, and which files are involved. When a file changes, it compares it to the previous version; if a method
    involved in some unit tests previously changes, it identifies those unit tests.
    You have to organize that process to associates test runs with coverage data, and re-run the unit tests identified, buts that a small matter of scripting. The reason for this is to enable the test coverage tool to operate with arbitrary testing frameworks.

You can do that on the build server to save time. More importantly, you can provide each developer with this, so that he can run just the tests required to validate the code he changes, before he checks in changes.

昇り龍 2024-12-07 05:52:59

Visual Studio 2010 Premium 和 Ultimate 有一个“测试影响”工具可以完成此任务。

Visual Studio 2010 Premium and Ultimate have a "Test Impact" tool that does exactly that.

绝影如岚 2024-12-07 05:52:59

在我们的环境中,我们使用 NCrunch http://www.ncrunch.net/

它构建项目并运行单元使用多线程在后台进行测试。
它以一种愉快的方式通知您失败的单元测试。

NCrunch 几乎可以满足您的需求。看看吧。

In our environment we use NCrunch http://www.ncrunch.net/

It builds the projects and runs the unit tests in the background using multiple threads.
It notifies you of failed unit tests in a pleasant way.

NCrunch does pretty much what you need. Have a look.

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