eRaisedToX
eRaisedToX

Reputation: 3361

How to run a single xunit C# test using dotnet test command line

Background: I am trying to run a C# unit test (test is using Xunit Framework), and my requirement is to run a single unit test and not all the tests in the whole dll.

Things I tried: I have tried few commands, but with no luck till now.

  1. I tried dotnet test "complete_path/someTestDll.dll" Result : This starts running all the test in the dll (expected but not desired)

  2. Tried dotnet test "complete_path/someTestDll.dll" \Tests: "Namespace.ClassName.MethodToRun" Result: Dll containing the test found but no test matches the filter.

  3. Tried dotnet test "complete_path/someTestDll.dll" --filter "FullyQualifiedName=Namespace.ClassName.MethodToRun" No test matching filter is found (again path to dll is alright)

  4. Tried dotnet test "complete_path/someTestDll.dll" --filter "DisplayName=Namespace.ClassName.MethodToRun"

Not only these but various mix and match of these with complete path, relative path, etc. etc. and almost wasted whole day.

NOTE: I know there are few answers on this over SO, but I have tried them all, from last day, and nothing seems to be working for me till now, so I had to come here to get some help.

Looks like I am missing something serious, Hopefully, I can get some answers which solves my issue.

Thanks a lot!!

enter image description here

Upvotes: 11

Views: 9500

Answers (3)

Jhonny Ramirez Zeballos
Jhonny Ramirez Zeballos

Reputation: 3186

1.- Run inside the solution.

dotnet test "project folder name" --filter=Namespace.ClassName.MethodName

2.- Run inside the project.

cd "project folder name"

dotnet test --filter=Namespace.ClassName.MethodName

Upvotes: 4

Frank Fernandez
Frank Fernandez

Reputation: 1

with xUnit, you can simply run the following command to run scenarios with specific tags

dotnet test "(path to the test dll file)" --filter Category=scenarioTag

You can create conditions for the filters as long as you put them inside of a string.

dotnet test "(path to the test dll file)" --filter "Category=scenarioTag|Category=scenarioTag2"

Upvotes: 0

Stev
Stev

Reputation: 1128

I was able to run a single xunit test via the developer command prompt using this template.

dotnet test "complete_path/someTestDll.dll" --filter "Namespace.ClassName.MethodName"

You can also run this command to see a full list of tests available, to help double check that the paths and names in your command are correct.

dotnet test "complete_path/someTestDll.dll" -t

Upvotes: 14

Related Questions