在 Visual Studio 中运行特定的单元测试 [英] Run specific unit test in Visual Studio

查看:46
本文介绍了在 Visual Studio 中运行特定的单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几十个单元测试,我想修复我现在正在处理的代码,但是每次我运行测试时,运行每个单元测试需要超过 30 秒(我认为反射是导致其中一些特别慢).我当前的测试和许多其他测试的运行时间不到一秒钟,但是禁用然后启用特定的单元测试很烦人.

I have dozens of unit tests, and I'd like to fix the code I am working on now, but every time I run the tests it takes over 30 seconds to run every unit test (I think reflection is the cause of some of these being especially slow). My current test and many other tests take less than one second to run, but it is annoying to disable and then enable specific unit tests.

有没有办法说,现在,运行一个特定的测试?"

Is there a way to say, "For now, run a single, specific test?"

我使用带有内置单元测试系统的 Visual Studio 2010.我通过右键单击任何代码并选择创建项目的创建单元测试"来创建测试.

I'm using Visual Studio 2010 with the built-in unit test system. I create tests by right-clicking any code and selecting "create unit test" which creates a project.

推荐答案

ResharperTest Driven .Net 在他们的 Visual Studio 测试运行器中都有这个功能.很可能还有其他 VS 插件.

Resharper and Test Driven .Net both have this feature in their visual studio test-runners. There may well be other VS plugins too.

根据这个回答(同样由 Jon Skeet 撰写)在 Visual Studio 中本机也是可能的.要调试单个测试:

According to this answer (By Jon Skeet no less) it is possible in Visual studio natively too. To debug a single test:

单击测试方法名称,然后按 Ctrl+R、Ctrl+T.(或转到当前上下文中的测试/调试/测试.)

Click on a test method name, then press Ctrl+R, Ctrl+T. (Or go to Test / Debug / Tests in Current Context.)

(基于 来自 Justin R 的评论 下面)来运行一个测试(而不是调试它),命令很简单:

(based on a comment from Justin R below) to run a test (as opposed to debugging it) the command is simply:

Ctrl+R,T

这篇关于在 Visual Studio 中运行特定的单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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