Search code examples
.netnunit

How to run NUnit test with parameters via dotnet test command?


I try to run tests via console but it doesn't work. I think that I need fix test parameter format. Parameter value can has few words. Could you help with correct string to run tests with parameters?

I have tried to change quotes and comma but it doesn't help.

Example:

dotnet test myProject --filter "Name=MyTest('My parameter value',null)"

Error:

MSBUILD : error MSB1006: Property is not valid.
Switch: null)

For switch syntax, type "MSBuild -help"

Also I have tried to encode comma to URL style but it doesn't work too...

Example:

dotnet test myProject --filter Name=MyTest('My parameter value'%2Cnull)"

Error:

An exception occurred while invoking executor 'executor://nunit3testexecutor/': Incorrect format for TestCaseFilter Missing Operator '|' or '&'. Specify the correct format and try again. Note that the incorrect format can lead to no test getting executed.

P.S. Problem only when test has parameters. Without parameters all works OK as it described in tutorials and official documents.


Solution

  • I have found the solution for myself. Because it's so complicated to find out how to work with quotes in the console (maybe it's impossible for NUnit), I have decided to use categories as an ID of tests. In this case, each test has a unique ID and I can run them easily across the console via the "Category" filter.