moodmosaic (Nikos Baxevanis)
Blog - About - Open Source - Bookmarks - Tags


Tuesday, 25 March 2014

AutoFixture 3.18 introduces a new glue library called Idioms.FsCheck.

It uses FsCheck to implement a reusable assertion that verifies (or at least, makes probable) that a method doesn’t return null:

[Theory, UnitTestConventions]
public void Scenario(ISpecimenBuilder builder)
    var sut = from x in new Methods<SomeClass>()
              select x.SomeMethod();
    var assertion = new ReturnValueMustNotBeNullAssertion(builder);
    Assert.Throws<ReturnValueMustNotBeNullException>(() =>

How it works

If a method is parameterless the assertion simply exercises its return value by invoking it. Otherwise, its return value is exercised against arbitrary values generated by FsCheck.

An injected instance of an ISpecimenBuilder (e.g. a Fixture instance) creates instances of the type containing the method if it’s declared as an instance method.

When needed, AutoFixture and FsCheck can be customized via their DSLs.



Idioms.FsCheck is available on NuGet:

PM> Install-Package AutoFixture.Idioms.FsCheck

This post has been filed under #autofixture #fscheck


Have feedback on this page? Let @nikosbaxevanis know on twitter. Need help or found a bug? Contact me.

© 2011-2018 Nikos Baxevanis. All written content on this site is provided under a Creative Commons ShareAlike license. All code is provided under a MIT license unless otherwise stated.