From d57ba7551dba024c13ba5131be5e82d8584181b0 Mon Sep 17 00:00:00 2001 From: Kurt Schelfthout Date: Mon, 30 Aug 2021 09:59:01 +0100 Subject: [PATCH] Add FsCheck.Xunit.TestOutputRunner. --- src/FsCheck.Xunit/FsCheck.Xunit.fsproj | 1 + src/FsCheck.Xunit/PropertyAttribute.fs | 3 ++- src/FsCheck.Xunit/Runner.fs | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/FsCheck.Xunit/Runner.fs diff --git a/src/FsCheck.Xunit/FsCheck.Xunit.fsproj b/src/FsCheck.Xunit/FsCheck.Xunit.fsproj index 12c6cd41..55df0925 100644 --- a/src/FsCheck.Xunit/FsCheck.Xunit.fsproj +++ b/src/FsCheck.Xunit/FsCheck.Xunit.fsproj @@ -8,6 +8,7 @@ + diff --git a/src/FsCheck.Xunit/PropertyAttribute.fs b/src/FsCheck.Xunit/PropertyAttribute.fs index 8fd054a9..7f734339 100644 --- a/src/FsCheck.Xunit/PropertyAttribute.fs +++ b/src/FsCheck.Xunit/PropertyAttribute.fs @@ -4,11 +4,12 @@ open System open System.Reflection open System.Threading.Tasks -open FsCheck open Xunit open Xunit.Sdk open Xunit.Abstractions +open FsCheck + type PropertyFailedException = inherit Exception new (testResult:FsCheck.TestResult) = { diff --git a/src/FsCheck.Xunit/Runner.fs b/src/FsCheck.Xunit/Runner.fs new file mode 100644 index 00000000..653eb4ed --- /dev/null +++ b/src/FsCheck.Xunit/Runner.fs @@ -0,0 +1,20 @@ +namespace FsCheck.Xunit + +open FsCheck + +/// A runner for FsCheck (i.e. that you can use as Config.Runner) which outputs +/// to Xunit's given ITestOutputHelper. +/// For example, { Config.QuickThrowOnFailure with Runner = TestOutputRunner(output) } +type TestOutputRunner(output: Xunit.Abstractions.ITestOutputHelper) = + interface IRunner with + member _.OnStartFixture t = + output.WriteLine (Runner.onStartFixtureToString t) + member _.OnArguments (ntest, args, every) = + output.WriteLine (every ntest args) + member _.OnShrink(args, everyShrink) = + output.WriteLine (everyShrink args) + member _.OnFinished(name,testResult) = + let resultText = Runner.onFinishedToString name testResult + match testResult with + | TestResult.True _ -> resultText |> output.WriteLine + | _ -> failwithf "%s" resultText \ No newline at end of file