我应该首先将单元测试编写为控制台应用程序吗?

发布于 2024-09-18 13:16:43 字数 287 浏览 2 评论 0原文

我正在调试一组 WCF 服务。最初,我创建了一些单元测试,但由于我使用线程,我经常收到“中止”或“停止”测试,而没有任何明确的解释(这是 Visual Studio 中的一个已知错误)。

我发现当我什至无法读取日志输出时调试服务非常具有挑战性,因此我快速编写了一个自定义 Assert 类并将所有单元测试转换为控制台应用程序。通过这种方式,我能够立即解决大量以前很难甚至不可能的简单问题。

所以我想知道首先将单元测试编写为(完全自动化)控制台应用程序,然后将其转换为真实的(在 VS 中启动单元测试时执行)测试是否是一个好主意。

I'm debugging a set of WCF services. Initially, I created some unit tests, but since I'm using threading I often receive "Aborted" or "Stopped" tests without any clear explanation why (this is a known bug in Visual Studio).

I found it extremely challenging to debug the services when I can't even read the log output, so I quickly wrote a custom Assert class and converted all unit tests to console applications. This way, I was able to fix a huge number of simple problems immediately that were hard to impossible before.

So I'm wondering if it is a good idea to write unit tests as (fully automated) console apps first and convert them to real (executes when launching unit tests in VS) tests later.

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

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

发布评论

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

评论(1

勿忘心安 2024-09-25 13:16:43

如果您想坚持使用独立的控制台应用程序,您可以采用一种万能的方法:将

  • MsUnitTest(或 NUnitTest)的应用程序类型更改为“控制台应用程序”,
  • 添加一个 public static void Main() 调用您感兴趣的单元测试。

该 exe 可以单独运行,也可以在单元测试 IDE 中运行。

我更喜欢独立的控制台运行程序,如 how-do-i-use- 中所述mstest 无视觉工作室

if you want to stick to the stand alone console app you can have a one fits all aproach: Change

  • the application type of the MsUnitTest (or NUnitTest) to "Console application"
  • add a public static void Main() that call your unittests you are interested in.

This exe is can run on its own or it runs in the unittest-ide.

I prefer a standalone consolerunner as described in how-do-i-use-mstest-without-visual-studio

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