使用功能C#执行所有单元测试

发布于 2025-02-04 16:07:08 字数 219 浏览 0 评论 0原文

是否可以在控制台应用程序中执行所有C#单元测试(Xunit)?因此,最终用户可以在运行程序时看到结果? 假设我们有简单的切换案例菜单,例如:

  1. 做某事,
  2. 做一些不同的
  3. 运行单元测试。

因此,当来自用户键盘的输入等于3个项目的所有单元测试时,执行了结果?

感谢您的帮助

Is there a way to execute all of the C# unit tests (xUnit) within the console application? So that the end user can see the results while running the program?
Let's say that we have simple switch case menu like:

  1. Do something,
  2. Do something different
  3. Run unit tests.

So that when the input from user's keyboard equals 3 all of the unit tests from the project are executed and the result is printed?

Thanks in an advance for the help

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

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

发布评论

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

评论(1

甩你一脸翔 2025-02-11 16:07:08

假设您的测试活在一个名为mytest.csproj的C#项目中,您将通过dotnet test myTest.csproj
如果您想在自己的应用程序中执行此操作,则可以使用process.start这样的:

if (chosenMenuItem == 3)
  Process.Start("dotnet", "test MyTest.csproj");

这将开始测试运行。

如果您也想获得测试输出,则可以按照以下答案: htttps://stackoverflow.com/a/a/4291965/ 4919526

Assuming that your tests live in a C# project called MyTest.csproj, you'd start them from the CLI via dotnet test MyTest.csproj.
If you want to do this from within your own application, you could use Process.Start like this:

if (chosenMenuItem == 3)
  Process.Start("dotnet", "test MyTest.csproj");

That will start the test run.

If you want to get the test output as well, you could follow this great answer: https://stackoverflow.com/a/4291965/4919526

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