Package | Version | Downloads |
---|---|---|
AutoFixture.Community.FSharp | ||
AutoFixture.Community.FSharp.Xunit |
This is a small library that builds on top of AutoFixture to add support
for F#-specific types.
Specifically, the important additions that are't currently handled well with vanilla AutoFixture
are:
- Discriminated Unions
- F# lists
Everything else seems to work pretty well out of the box.
Can be inserted onto any existing IFixture
by doing the following
let fixture = Fixture()
//...
fixture.Customizations.Add(FSharpSpecimenBuilder(fixture))
A pre-made fixture with only the F# features applied.
Helper functions for creating random data inline, e.g.:
type MyDto =
{ Foo : int
Bar : string
Baz : DateTime }
[<Fact>]
let ``My test method when Foo is 5`` () =
// Generate random values explicitly for specific properties
let myDto =
{ Foo = 5
Bar = randVal()
Baz = randVal() }
// Or generate a full random value and only override specific properties
let otherDto =
{ randVal<MyDto>() with Foo = 5 }
~~// Do assertions~~
Thanks to F#'s type system, most of the time you can omi~~~~t the type arguments. Similar helper functions include:
randVal<'a>()
: create a single random valuerandVals<'a>()
: create an'a seq
randValsN<'a> (n: int)
: create an'a seq
that isn
elements longrandValExceptWhere<'a> (fn: 'a -> bool)
: create a single random value for whichfn
returns false.randValExcept<'a> (x: 'a)
: create a random value that is notx
randValsExceptWhere<'a> (fn: 'a -> bool)
: create an infinite sequence of random values wherefn
returns falserandValsExcept<'a> (x: 'a)
: create an infinite sequence of random values exceptx
randValsNExceptWhere<'a> (n: int) (fn: 'a -> bool)
: create a sequence ofn
random values wherefn
returns falserandValsNExcept<'a> (n: int) (x: 'a)
: create a sequence ofn
random values except forx
This package defines just two attributes:
AutoDataFSharpAttribute
InlineAutoDataFSharpAttribute
Which respectively correspond to the AutoDatAttribute
and InlineAutoDataAttribute
from AutoFixture.Xunit2