如何在 Visual Studio 中分别运行不同文件夹/项目中的(单元)测试?

发布于 2024-07-04 06:16:40 字数 687 浏览 10 评论 0原文

Visual Studio 文件夹结构

我需要一些关于如何在 Visual Studio 中轻松分离单元测试和集成测试的测试运行的建议。 通常或总是,我构建如上图所示的解决方案:用于单元测试和集成测试的单独项目。 单元测试运行非常频繁,而集成测试自然会在上下文正确对齐时运行。

我的目标是以某种方式能够配置当我使用键盘快捷键时运行哪些测试(或测试文件夹)。 测试最好由图形测试运行程序 (ReSharpers) 运行。 例如,

  • Alt+1 运行项目 BLL.Test 中的测试,
  • Alt+2 运行项目 DAL.Tests 中的测试,
  • Alt+3 运行它们两者(即 [Tests] 文件夹中的所有测试,
  • Alt+4 运行文件夹 [Tests.Integration] 中的测试

可以选择仅运行所选文件夹或项目中的测试,方法是右键单击它并选择“运行测试”,但可以通过键盘执行此操作。命令和图形测试运行器会很棒

TestDriven.net 测试运行输出

目前我使用 VS2008、ReSharper 4 和 nUnit。但对于一般设置的建议当然也是值得赞赏的。

Visual Studio folder structure

I need some advice as to how I easily can separate test runs for unit tests and integration test in Visual Studio. Often, or always, I structure the solution as presented in the above picture: separate projects for unit tests and integration tests. The unit tests is run very frequently while the integration tests naturally is run when the context is correctly aligned.

My goal is to somehow be able configure which tests (or test folders) to run when I use a keyboard shortcut. The tests should preferably be run by a graphical test runner (ReSharpers). So for example

  • Alt+1 runs the tests in project BLL.Test,
  • Alt+2 runs the tests in project DAL.Tests,
  • Alt+3 runs them both (i.e. all the tests in the [Tests] folder, and
  • Alt+4 runs the tests in folder [Tests.Integration].

TestDriven.net have an option of running just the test in the selected folder or project by right-clicking it and select Run Test(s). Being able to do this, but via a keyboard command and with a graphical test runner would be awesome.

TestDriven.net test run output

Currently I use VS2008, ReSharper 4 and nUnit. But advice for a setup in the general is of course also appreciated.

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

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

发布评论

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

评论(4

带刺的爱情 2024-07-11 06:16:40

这是一个有点繁琐的解决方案,但您可以配置一些 外部工具用于您要运行的每组测试。 我不确定您是否能够以这种方式启动 ReSharper 测试运行程序,但您可以运行 nunit 的控制台版本。 设置完这些工具后,您可以将键盘快捷键分配给命令“Tools.ExternalCommand1”、“Tools.ExternalCommand2”等。

这不会很好地扩展,并且更改起来很尴尬 - 但它会给您键盘快捷键用于运行您的测试。 确实感觉应该有一种更简单的方法来做到这一点。

This is a bit of fiddly solution, but you could configure some external tools for each of group of tests you want to run. I'm not sure if you'll be able to launch the ReSharper test runner this way, but you can run the console version of nunit. Once you have of those tools setup, you can assigned keyboard shortcuts to the commands "Tools.ExternalCommand1", "Tools.ExternalCommand2", etc.

This wont really scale very well, and it's awkward to change - but it will give you keyboard shortcuts for running your tests. It does feel like there should be a much simpler way of doing this.

高跟鞋的旋律 2024-07-11 06:16:40

实际上,我通过使用绑定到宏的键盘命令自己找到了一种解决方案。 宏是从菜单“工具”>“宏”>“记录临时宏”录制的。 录制时,我选择了 [Tests] 文件夹并运行 ReSharpers UnitTest.ContextRun。 这产生了以下宏,

Sub TemporaryMacro()
    DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate
    DTE.ActiveWindow.Object.GetItem("TestUnitTest\Tests").Select(vsUISelectionType.vsUISelectionTypeSelect)
    DTE.ExecuteCommand("ReSharper.UnitTest_ContextRun")
End Sub

然后将其绑定到“工具”>“选项”>“环境”>“键盘”中自己的键盘命令。

然而,更棒的是一个更通用的解决方案,我可以准确配置要运行的项目/文件夹/类以及何时运行。 例如通过 xml 文件。 然后可以轻松地将其签入版本控制并分发给参与该项目的每个人。

I actually found kind of a solution for this on my own by using keyboard command bound to a macro. The macro was recorded from the menu Tools>Macros>Record TemporaryMacro. While recording I selected my [Tests] folder and ran ReSharpers UnitTest.ContextRun. This resulted in the following macro,

Sub TemporaryMacro()
    DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate
    DTE.ActiveWindow.Object.GetItem("TestUnitTest\Tests").Select(vsUISelectionType.vsUISelectionTypeSelect)
    DTE.ExecuteCommand("ReSharper.UnitTest_ContextRun")
End Sub

which was then bound to it's own keyboard command in Tools>Options>Environment>Keyboard.

However, what would be even more awesome is a more general solution where I can configure exactly which projects/folders/classes to run and when. For example by the means of an xml file. This could then easily be checked in to version control and distributed to everyone who works with the project.

岁月如刀 2024-07-11 06:16:40

我从未使用过这个,但也许它可以帮助......

http://www.codeplex.com/VS2008UnitTestGUI< /a>

“项目描述
该项目是关于在使用 Visual Studio 2008 编码的多个 .NET 单元测试程序集中运行所有单元测试。”

I have never used this but maybe it could help....

http://www.codeplex.com/VS2008UnitTestGUI

"Project Description
This project is about running all unit test inside multiple .NET Unit tests assembly coded with Visual Studio 2008."

栩栩如生 2024-07-11 06:16:40

您可以使用 VS 宏来解析 XML 文件,然后使用 /fixture 命令行参数调用 nunit.exe 以指定要运行的类或生成选择保存文件并使用该文件运行 nunit。

You can use a VS macro to parse the XML file and then call nunit.exe with the /fixture command line argument to specify which classes to run or generate a selection save file and run nunit using that.

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