Skip to content

Commit d57ba75

Browse files
Add FsCheck.Xunit.TestOutputRunner.
1 parent 1b82d77 commit d57ba75

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/FsCheck.Xunit/FsCheck.Xunit.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</PropertyGroup>
99
<ItemGroup>
1010
<Compile Include="AssemblyInfo.fs" />
11+
<Compile Include="Runner.fs" />
1112
<Compile Include="PropertyAttribute.fs" />
1213
<Compile Include="CheckExtensions.fs" />
1314
</ItemGroup>

src/FsCheck.Xunit/PropertyAttribute.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ open System
44
open System.Reflection
55
open System.Threading.Tasks
66

7-
open FsCheck
87
open Xunit
98
open Xunit.Sdk
109
open Xunit.Abstractions
1110

11+
open FsCheck
12+
1213
type PropertyFailedException =
1314
inherit Exception
1415
new (testResult:FsCheck.TestResult) = {

src/FsCheck.Xunit/Runner.fs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace FsCheck.Xunit
2+
3+
open FsCheck
4+
5+
/// A runner for FsCheck (i.e. that you can use as Config.Runner) which outputs
6+
/// to Xunit's given ITestOutputHelper.
7+
/// For example, { Config.QuickThrowOnFailure with Runner = TestOutputRunner(output) }
8+
type TestOutputRunner(output: Xunit.Abstractions.ITestOutputHelper) =
9+
interface IRunner with
10+
member _.OnStartFixture t =
11+
output.WriteLine (Runner.onStartFixtureToString t)
12+
member _.OnArguments (ntest, args, every) =
13+
output.WriteLine (every ntest args)
14+
member _.OnShrink(args, everyShrink) =
15+
output.WriteLine (everyShrink args)
16+
member _.OnFinished(name,testResult) =
17+
let resultText = Runner.onFinishedToString name testResult
18+
match testResult with
19+
| TestResult.True _ -> resultText |> output.WriteLine
20+
| _ -> failwithf "%s" resultText

0 commit comments

Comments
 (0)