AutoFixture: NUnit Values and AutoData doesn't work
The AutoData overrides the [Values] tag of NUnit
[Test, AutoData]
public void Test(string name, [Values(1, -1)] int num)
num will be set by the AutoData and not from the Values
About this issue
- Original URL
- State: open
- Created 9 years ago
- Reactions: 3
- Comments: 21 (19 by maintainers)
I finally was able to find a solution to this issue in a way that satisfies the many requirements.
At the moment I have only a LinqPad script with the needed classes but I plan to make a PR out of it. The only issue is that it required few breaking changes and I’m discussing with @aivascu how to go forward.
I have focused on the
AutoDataAttribute
for now but I don’t think it will take long to bring the same modifications toInlineAutoDataAttribute
.The new
AutoDataAttribute
generates as many tests as the combination of the inputs of the method parameters. If a parameter is given no value from a value generator, AutoFixture is used. Also, it’s possible to freeze a value generated from the NUnit attributes.Here are some examples. For each example, I show a LinqPad Dump of the generated test runs.
As you can see from the snippets, the
Values
,Range
andValueSource
are used to generate individual test runs. Also, the values they provide are used to name the test so that each test run has a unique name.What’s left to do:
InlineAutoData
, requiredValueSource
with methods with parameters fed by AutoFixture, not sure if possibleEDIT:
Following @steph4nc line, I created this gist
The small unit test I created is correctly executed and interacts nicely with the other NUnit attributes (in the example I used
Values
andRange
).Users should be able to inherit from this attribute and create their own version with a customized Fixture.
Notable to report, the object is created only once and used for all the iterations.
Here are some screenshots from Visual Studio 2017 Enterprise
ReSharper test session
Live testing
Console