Making Verify play nice with AutoFixture #517
Replies: 6 comments 16 replies
-
side note: u need to |
Beta Was this translation helpful? Give feedback.
-
@SimonCropp. I get a feeling that my |
Beta Was this translation helpful? Give feedback.
-
would it make it easier if i had an approach to ignore certain parameters? eg
|
Beta Was this translation helpful? Give feedback.
-
comments fixed |
Beta Was this translation helpful? Give feedback.
-
so with the relaxed param checking, do we still want/need a Verify.AutoFixture extension? |
Beta Was this translation helpful? Give feedback.
-
Hi all
UPDATE: after some tweaks to Verify by Simon, this post has been edited to reflect what is currently required to get AutoFixture and Verify to work together.
That also means most of the discussion below in the comments are not relevant any more.
I want to share how I have managed to get AutoFixture and Verify to work well together:
AutoFixture is a tool that we use quite a lot at work to generate random data for tests, where the data itself is not important, but just needs to be there to support the test. These test data change with every run of a test, which, for the most part, works well with Verify, since it scrubs things like
Guid
andDateTime
automatically.However, when AutoFixture generates strings for a test argument or property in a class, it does so like this.
propertyName2cbc7050-919f-4fd3-867e-f69e311c9647
, which Verify is not able to scrub and turn into something likepropertyNameGUID_1
.This means that the following DOES NOT work out of the box:
The problem is that
randomUserName
will be set to something like thisrandomUserName2cbc7050-919f-4fd3-867e-f69e311c9647
, but with a newGUID
on every run.Note: the
AutoData
andInlineAutoData
attribute is part of theAutoFixture.Xunit2
package.AutoFixture Extensions
To solve the problem, I created an extensions for AutoFixture.
First we need to adjust AutoFixture's data attributes to generate strings that Verify's inline GUID scrubber can scrub.
These
AutoData
andInlineAutoData
attributes (with the same names as the ones in the AutoFixture.Xuni2 package for easy drop in) does this:The basic change is to add an underscore (
_
) between the "seed" and the generated GUID. In therandomUserName
example, it will now generate ``randomUserName_2cbc7050-919f-4fd3-867e-f69e311c9647` which Verify can scrub.Finally, we can enable inline scrubbing of GUIDs in our module initializer:
At this point, the tests at the top of the post will work as expected.
Beta Was this translation helpful? Give feedback.
All reactions