如何在一个 VS 解决方案中运行 NUnit 测试之前启动控制台应用程序?

发布于 2024-11-28 01:43:58 字数 1413 浏览 1 评论 0原文

在 VS2010 中,您可以指定多个启动项目(右键单击解决方案并在“启动项目”区域中选择适当的选项)。

如果您按 F5,效果很好,但对于 NUnit 测试,我还没有找到在运行测试之前启动这些项目的方法。有办法吗?

限制:

  1. 我不想从 dos 运行控制台应用程序,因为我需要调试支持。

  2. 我不想打开单独的解决方案。我的推理是,解决方案和解决方案之间的切换存在更多摩擦。确保编辑进入正确的解决方案。 VS2010 在检查文件何时更改方面做得很好,但是,拥有一种与按 F5 时相同的方式工作的集成调试体验会更容易。

目前我正在将 NUnit 与 Resharper 6 一起使用。

希望有一个我缺少的选项。

感谢您查看此内容。


更新:

所以目前看来是一种不受支持的情况。目前我正在考虑将测试也作为控制台应用程序启动。也许我会创建手动指定一个测试或所有测试的方法。

即使在测试运行程序之外运行,也能够获得有关成功/失败的报告,那就太好了。是否又回到手动执行此操作?

解决方案

Pedro 在解决方案帖子的评论中发布了这些链接:

对于 *C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0* 中的这些文件:

  • nunit.exe.config

  • < p>nunit-x86.exe.config(对我来说很重要)

我进行了这些设置更改:

下添加:

    <startup>
      <supportedRuntime version="v4.0.30319" />
    </startup>

并在下添加:

    <loadFromRemoteSources enabled="true" />

In VS2010 you can specify multiple startup projects (right-click on Solution & selelct appropriate options in the "Startup Project" area).

That works fine if you hit F5, but for NUnit tests I haven't yet found a way to startup those projects before running the tests. Is there a way?

Constraints:

  1. I don't want to run the console apps from dos, as I want debug support.

  2. I don't want to have a seperate solution open. My Reasoning here is just that there's a little more friction switching between solutions & making sure edits go in the right solution. VS2010 does a good job of checking when files have changed, but, it'll just be easier to have one integrated debug experience that works the same way as when hitting F5.

Currently I'm using NUnit with Resharper 6.

Hopefully there's an option somewhere that I'm missing.

Thanks for taking a look at this.


UPDATE:

So it looks like an unsupported situation at the moment. Presently I'm looking at starting the tests as console applications as well. Probably I'll create way of secifying one test or all tests manually.

It'd be nice to be able to get a report on success/failure even if run outside of the test runner. Is it back to doing this manually?

A SOLUTION

Pedro posted these links in the comments to solution posts:

For these files in *C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0*:

  • nunit.exe.config

  • nunit-x86.exe.config (IMPORTANT FOR ME)

I made these settings changes:

Under <configuration> add:

    <startup>
      <supportedRuntime version="v4.0.30319" />
    </startup>

and under <runtime> add:

    <loadFromRemoteSources enabled="true" />

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

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

发布评论

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

评论(3

风轻花落早 2024-12-05 01:43:58

在另一个问题中,我发布了一个解决方案只需按 F5 即可运行 NUnit GUI。如果您随后将单元测试和控制台应用程序项目设置为同时运行,您应该会获得所需的结果。

In another question, I posted a solution for running the NUnit GUI simply by pressing F5. If you then set the unit tests and console app projects to both run, you should get the desired outcome.

滴情不沾 2024-12-05 01:43:58

According to this page, NUnit has a [TestFixtureSetUp] attribute that will run once before running any other unit tests. While I haven't used NUnit myself, I would think you should be able to launch any necessary prerequisite programs in a method tagged with this attribute. As the code is executed just like any other, I would think it could be debugged like any other block of code as well.

回忆凄美了谁 2024-12-05 01:43:58

由于您使用 Resharper 进行测试运行,我很好奇您是否尝试过类似的操作。将解决方案的启动项目设置为所需的控制台应用程序,然后按 F5。然后,右键单击您有兴趣运行的测试项目/文件,然后单击“运行单元测试”。

看起来 Resharper 隐藏了“调试单元测试”选项,而解决方案是运行状态,但如果您希望调试控制台应用程序方面的内容,这可能适合您(完全未经测试的理论)在此刻)。我认为使用这种方法调试测试方面的事情会很不幸。

当然,这与 Resharper 的测试运行程序相关,如果您希望在持续集成构建系统上或通过 NUnit GUI/控制台执行此操作,则此方法甚至无法帮助您。

Since you are using Resharper as your test running, I'm curious if you have tried something along these lines. Set your solution's startup projects to be the console application(s) you want, and press F5. Then, right-click on the test project/file that you are interested in running and then click 'Run Unit Tests.'

It looks like Resharper hides the 'Debug Unit Tests' option while the solution is the running state, but if you are looking to debug the console app side of things, this might work for you (totally untested theory at this point). I would assume you would be out of luck debugging the test side of things though using this method.

And of course this is tied to Resharper's test runner, if you were looking to do this on a continuous integration build system or via the NUnit GUI/Console, this method wouldn't even come close to helping you out.

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