Andreas-Dorfer / fscheck-mstest

Integrates FsCheck with MSTest.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NuGet Package

AD.FsCheck.MSTest

Integrates FsCheck with MSTest. Inspired by FsCheck's own Xunit integration.

NuGet Package

PM> Install-Package AndreasDorfer.FsCheck.MSTest -Version 1.1.2

TLDR

Without AD.FsCheck.MSTest your tests look like this:

using FsCheck;

[TestClass]
public class PlusTest
{
    [TestMethod]
    public void Commutative() => Prop.ForAll((int a, int b) => a + b == b + a).QuickCheckThrowOnFailure();
}

With AD.FsCheck.MSTest your tests look like this:

using AD.FsCheck.MSTest;

[TestClass]
public class PlusTest
{
    [Property]
    public void Commutative(int a, int b) => Assert.AreEqual(a + b, b + a);
}

Run Configuration

You can configure how your properties are run using either the PropertyAttribute on a method, or the PropertiesAttribute on a test class:

  • MaxNbOfTest
  • MaxNbOfFailedTests
  • StartSize
  • EndSize
  • Replay
  • Verbose
  • QuietOnSuccess
[Properties(MaxNbOfTest = 1000)]
public class PlusTest
{
    [Property(Replay = "760375822,297103040", Verbose = true)]
    public void Commutative(int a, int b) => Assert.AreEqual(a + b, b + a);
}

Lifecycle

AD.FsCheck.MSTest adds two lifecycle attributes: PropertyInitialize and PropertyCleanup.

[TestClass]
public class PlusTest
{
    [AssemblyInitialize]
    public static void AssemblyInitialize(TestContext tc)
    { /* (1) .. before any test in the assembly */ }

    [PropertyInitialize]
    public static void PropertyInitialize(string propName)
    { /* (2) .. before each property in this class */ }

    [TestInitialize]
    public void TestInitialize()
    { /* (3) .. before each individual run of a property in this class */ }

    [Property]
    public void Commutative(int a, int b)
    { /* (4) */ }

    [TestCleanup]
    public void TestCleanup()
    { /* (5) .. after each individual run of a property in this class */ }

    [PropertyCleanup]
    public static void PropertyCleanup(string propName)
    { /* (6) .. after each property in this class */ }

    [AssemblyCleanup]
    public static void AssemblyCleanup()
    { /* (7) .. after all tests in the assembly */ }
}

Examples

Limitations

A property's return type must be void / Task.

bool / Task<bool> and Property / Task<Property> are not supported.

About

Integrates FsCheck with MSTest.

License:MIT License


Languages

Language:C# 96.5%Language:F# 3.5%