[英]Execute all unit test using a function C#
Is there a way to execute all of the C# unit tests ( xUnit
) within the console application?有没有办法在控制台应用程序中执行所有 C# 单元测试(
xUnit
)? So that the end user can see the results while running the program?这样最终用户可以在运行程序时看到结果吗? Let's say that we have simple
switch case
menu like:假设我们有简单的
switch case
菜单,例如:
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?这样当用户键盘的输入等于 3 时,项目中的所有单元测试都会执行并打印结果?
Thanks in an advance for the help预先感谢您的帮助
Assuming that your tests live in a C# project called MyTest.csproj
, you'd start them from the CLI via dotnet test MyTest.csproj
.假设您的测试位于名为
MyTest.csproj
的 C# 项目中,您将通过dotnet test MyTest.csproj
从 CLI 启动它们。
If you want to do this from within your own application, you could use Process.Start
like this:如果您想在自己的应用程序中执行此操作,可以像这样使用
Process.Start
:
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如果您还想获得测试输出,您可以遵循这个很好的答案: https ://stackoverflow.com/a/4291965/4919526
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.