Say I have a test:
[Theory]
[InlineData("one")]
[InlineData("two")]
public void ShouldSelectSingleTheoryFromDotnetTest(string s)
{
Assert.True(true);
}
I want to execute just the test with Theory data = "one" from the command line using dotnet test...
. Is this possible?
I know we can select tests using Traits, but I cannot see how to associate a single trait with each single line of Theory data.
As a workaround I thought maybe I could use the technique of dynamically skipping tests, but still to do that I'd need to read an argument from the command line and can't see how to do that either. One workaround to that, might be to set an environment variable on the command line, then run the tests using the dynamic skipping pattern, where the dynamic skip logic would read the command line argument. But that is very clunky.
You can use
--filter
parameter ofdotnet test
.First of all use
-t|--list-tests
to see the test names, then you will get something like:Then you can use this information to filter on the
DisplayName
.Was not able to figure out how to escape double quotes and parenthesis in the name so used "workaround" to combine filtering on
FullyQualifiedName
andDisplayName
:Which gives me the following output:
Compared to one without filter:
UPD
Was able to figure out the double quotes escaping, so parameter names can be used - replace double quotes with
%22
:UPD2
Courtesy of @Jan Zakrzewski:
Parenthesis can be escaped by using
\
i.e.\(
and\)
.Which makes the full filter looking like the following: