如何在Visual Studio中将单元测试与集成测试分开? [英] How do you separate unit tests from integration tests in Visual Studio?

查看:136
本文介绍了如何在Visual Studio中将单元测试与集成测试分开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Visual Studio 2008测试项目来存储测试.最近,我意识到我的许多单元测试实际上都是集成测试,因为它们依赖于外部资源(例如文件系统,SQL Server,注册表).

I've been using Visual Studio 2008 Test projects to store my tests. Lately I've realized that a lot of my unit tests are in fact integration tests because they rely on external sources (e.g. file system, SQL server, registry).

我的问题是,从单元测试中分离出集成测试的好方法是什么?

My question is, what is a good approach to separating out integration tests from unit tests?

理想情况下,我只希望单元测试显示在测试视图"中,因为我在开发过程中经常运行它们.另一方面,我不希望在测试视图中进行集成测试,因为我只会很少运行它们,例如当我要放弃构建时.

Ideally I want only the unit tests to show up in the Test View, because I run them frequently during development. The integration tests on the other hand I don't want in the Test View because I will only run them infrequently, e.g. when I'm about to make a build drop.

推荐答案

将它们保留在单独的项目中,并将集成测试项目保留在日常的Visual Studio解决方案之外.

Keep them in separate projects, and keep the integration testing projects out of your day-to-day Visual Studio solutions.

当您希望运行集成测试时,可以使用包含它们的其他解决方案.如果您不想等待第二个VS实例加载,则可以从命令行运行它们.

When you wish to run the integration tests, you can use a different solution that includes them. If you don't want to wait for a second instance of VS to load, you can run them from the command-line.

这篇关于如何在Visual Studio中将单元测试与集成测试分开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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