Ignore only class level parameters in NUnit tests is not possible
tom-englert opened this issue · 1 comments
tom-englert commented
Describe the bug
It's not possible to ignore only the class level parameters of an NUnit test, but include the method level parameters.
Minimal Repro
These are the combinations I tried:
[TestFixture("1")]
[TestFixture("2")]
public class ClassLevelParams2(string arg1)
{
[TestCase("3")]
[TestCase("4")]
public Task IgnoreClassLevelParametersOnly_Attempt1(string arg2) =>
Verify(arg2)
.IgnoreParametersForVerified(arg1);
[TestCase("3")]
[TestCase("4")]
public Task IgnoreClassLevelParametersOnly_Attempt2(string arg2) =>
Verify(arg2)
.IgnoreParametersForVerified(arg2);
[TestCase("3")]
[TestCase("4")]
public Task IgnoreClassLevelParametersOnly_Attempt3(string arg2) =>
Verify(arg2)
.UseParameters(arg2);
[TestCase("3")]
[TestCase("4")]
public Task IgnoreClassLevelParametersOnly_Attempt4(string arg2) =>
Verify(arg2)
.UseParameters(arg2)
.DisableRequireUniquePrefix();
}
These are the files created:
ClassLevelParams2.IgnoreClassLevelParametersOnly_Attempt1.verified.txt
ClassLevelParams2.IgnoreClassLevelParametersOnly_Attempt2.verified.txt
ClassLevelParams2.IgnoreClassLevelParametersOnly_Attempt3_arg1=3.verified.txt
ClassLevelParams2.IgnoreClassLevelParametersOnly_Attempt3_arg1=4.verified.txt
ClassLevelParams2.IgnoreClassLevelParametersOnly_Attempt4_arg1=3.verified.txt
ClassLevelParams2.IgnoreClassLevelParametersOnly_Attempt4_arg1=4.verified.txt
Attempt 1 & 2 fail because no parameters are used at all.
Attempt 3 fails partially with " System.Exception : The prefix has already been used"
Attempt 4 works, however like in 3 the name of the parameter is wrong, should be arg2
tom-englert commented
After looking at the code again, it seems that:
- The arguments specified in the method
IgnoreParametersForVerified
actually don't have any effect. UseParameters
implicitly maps parameters by index, where the first parameter here is the class parameter.
So I managed to do this workaround:
[TestCase("3")]
[TestCase("4")]
public Task IgnoreClassLevelParametersOnly_Workaround(string arg2) =>
Verify(arg2)
.UseParameters("Any", arg2)
.DisableRequireUniquePrefix();
However it would be more intuitive use the parameters of IgnoreParametersForVerified
and allow to specify parameter names to be skipped.