1

I have written an NUnit test. Now, I need to run those tests from my C# code. My tests are built using .net core 3.1.

I need to invoke two commands from my C# code. 1) dotnet test 2) dotnet test --filter "Category=CategoryA&Category=CategoryB"

How to do this from C#?

I am trying to do something like this

namespace MyNameSpace
{
  class MyProgram
  {
     public void RunTests()
     {
        //run dotnet test

       //run dotnet test --filter "Category=CategoryA&Category=CategoryB" 

     }
  }
}
Ayan
  • 115
  • 2
  • 10
  • Look at [Process.Start](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.start?view=netcore-3.1) – vc 74 Jun 09 '20 at 11:03
  • @vc74 This link doesn't help – Ayan Jun 09 '20 at 11:40
  • 1
    @Ayan It should help. If it doesn't, please explain why – canton7 Jun 09 '20 at 12:17
  • @canton7 It doesn't talk about how to start the .net process that will run dotnet test. I need to know which process I need to start. Is it dotnet.exe ? or some other process and then I need to know the syntax to run dotnet test and dotnet test --filter in that process. – Ayan Jun 09 '20 at 13:02
  • 1
    It tells you how to run executables. `dotnet` is an executable. – canton7 Jun 09 '20 at 13:03
  • 1
    Yes. `dotnet test` runs the executable `dotnet.exe`, passing in the command-line argument `test`. If you run `dotnet test --filter "foo"`, that invokes `dotnet.exe` passing in the command-line arguments `test --filter "foo"` – canton7 Jun 09 '20 at 13:11
  • @canton7 How to pass the path to the dll where the tests reside ? Currently I am doing like this ProcessStartInfo processStartInfo = new ProcessStartInfo("dotnet.exe"); processStartInfo.Arguments = "test" + " " + dllpath; But, this is not working. – Ayan Jun 09 '20 at 13:18
  • What's the equivalent command you run from the command-line, to which you pass the dll where the tests reside? – canton7 Jun 09 '20 at 13:19

0 Answers0