I'd like to run test method with only one set of params from a testcase.
I'm using NUnit Console 3.4.1.
Example of code:
[Category("SmokeTests")]
[TestCase("1 param", "2 param", "3 param")]
[TestCase("aaa", "bbb", "ccc")]
public void TestMethod(string a, string b, string c)
{
// do something
}
Command-line to be run:
nunit3-console.exe UiTests.dll --where "cat==SmokeTests and name==TestMethod(\"aaa\", \"bbb\", \"ccc\")" --result C:\temp\result.xml
Currently NUnit returns an error
Unexpected token '(' at position 50 in selection expression.
You were very close to the answer.
Your query was
--where "cat==SmokeTests and name==TestMethod(\"aaa\", \"bbb\", \"ccc\")"
There are three things wrong with the query:
You were right to think that the quotes need to be escaped with backslashes (\"
), but due to the way the arguments are interpreted, the backslashes themselves need to be escaped too (\\\"
).
To get around the
Unexpected token '(' at position 50 in selection expression.
you have to also wrap the name
parameter in quotes (these quotes only need to be escaped once).
When NUnit constructs its name for a method, it comma-separates the arguments, but without spaces. The name of the test you're trying to run in your example is
TestMethod("aaa","bbb","ccc")
not
TestMethod("aaa", "bbb", "ccc")
The query that should work, then, is:
--where "cat==SmokeTests and name==\"TestMethod(\\\"aaa\\\",\\\"bbb\\\",\\\"ccc\\\")\""
The arguments passed into nunit3-console.exe
are then:
--where
cat==SmokeTests and name=="TestMethod(\"aaa\",\"bbb\",\"ccc\")"
then NUnit can parse the name
arugment, handling the escaped quotes, and running the test you desire.
Reference: Test Selection Language in the NUnit documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With