Created
August 4, 2014 13:10
-
-
Save acrees/ba2450718fddc6d6f938 to your computer and use it in GitHub Desktop.
Naive xUnit.net test runner (console)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "bin/Debug/System.Runtime.dll" | |
#r "bin/Debug/xunit.abstractions.dll" | |
#r "bin/Debug/xunit.assert.dll" | |
#r "bin/Debug/xunit.core.dll" | |
#r "bin/Debug/xunit.execution.dll" | |
open System | |
open System.IO | |
open System.Reflection | |
open Xunit.Sdk | |
open Xunit.Abstractions | |
let path = Path.Combine("bin", "debug", "MyApp.Test.dll") | |
type Options () = | |
interface ITestFrameworkOptions with | |
member x.GetValue(name, defaultValue) = defaultValue | |
member x.SetValue(name, value) = () | |
let mutable testResults:TestResultMessage list = [] | |
let printResults (x:TestAssemblyFinished) = | |
let time = x.ExecutionTime.ToString("0.000") | |
let cPass = x.TestsRun - x.TestsFailed - x.TestsSkipped | |
let cFail = x.TestsFailed | |
printfn "Ran %d tests in %s seconds; %d passed and %d failed." | |
x.TestsRun time cPass cFail | |
if x.TestsFailed = 0 then Environment.Exit(0) | |
else | |
testResults | |
|> List.fold (fun acc n -> match n with | :? TestFailed as f -> f::acc | _ -> acc) [] | |
|> ignore | |
Environment.Exit(-1); | |
let handleRunningMessage (msg:IMessageSinkMessage) = | |
match msg with | |
| :? TestResultMessage as x -> testResults <- x :: testResults | |
| :? TestAssemblyFinished as x -> printResults x | |
| _ -> () | |
let fx = new XunitTestFramework() | |
let exec = AssemblyName.GetAssemblyName(path) |> fx.GetExecutor | |
let msg = new DelegatingMessageSink(null, (fun x -> handleRunningMessage x)) | |
exec.RunAll(msg, Options (), Options ()) | |
while true do () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment