简体   繁体   中英

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? 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM