diff --git a/docs/content/reporting.fsx b/docs/content/reporting.fsx index bbcd854c..c73ec0c6 100644 --- a/docs/content/reporting.fsx +++ b/docs/content/reporting.fsx @@ -44,3 +44,13 @@ open reporters reporter <- new TeamCityReporter() :> IReporter //screenshot is TODO + +(** +JUnit Reporter +----------------- +Produces test results in basic JUnit format. Compatible with CircleCI. +*) + +open configuration +open reporters +reporter <- new JUnitReporter("./TestResults.xml") :> IReporter \ No newline at end of file diff --git a/src/canopy/reporters.fs b/src/canopy/reporters.fs index 82153f15..a0c49ba4 100644 --- a/src/canopy/reporters.fs +++ b/src/canopy/reporters.fs @@ -385,8 +385,10 @@ type JUnitReporter(resultFilePath:string) = let consoleReporter : IReporter = new ConsoleReporter() :> IReporter - let passedTests = ResizeArray<_>() - let failedTests = ResizeArray<_>() + let testStopWatch = System.Diagnostics.Stopwatch() + let testTimes = ResizeArray() + let passedTests = ResizeArray() + let failedTests = ResizeArray() interface IReporter with @@ -409,15 +411,19 @@ type JUnitReporter(resultFilePath:string) = member this.summary minutes seconds passed failed skipped = consoleReporter.summary minutes seconds passed failed skipped - let testCount = passed + failed + let getTestTime test = + testTimes.Find(fun (t, _) -> test = t) |> snd let passedTestsXml = passedTests - |> Seq.map(sprintf "") + |> Seq.map(fun id -> sprintf "" id (getTestTime id)) let failedTestsXml = failedTests - |> Seq.map(fun (ex, id) -> sprintf "%s" id ex.Message) + |> Seq.map(fun (ex, id) -> sprintf "%s" id (getTestTime id) ex.Message) + let testCount = passed + failed + let testTimeSum = testTimes |> Seq.sumBy snd let allTestsXml = String.Join(String.Empty, Seq.concat [passedTestsXml; failedTestsXml]) - let xml = sprintf "%s" testCount allTestsXml + let xml = + sprintf "%s" testCount testTimeSum allTestsXml let resultFile = System.IO.FileInfo(resultFilePath) resultFile.Directory.Create() consoleReporter.write <| sprintf "Saving results to %s" resultFilePath @@ -434,8 +440,14 @@ type JUnitReporter(resultFilePath:string) = member this.testStart id = consoleReporter.testStart id + testStopWatch.Reset() + testStopWatch.Start() + + member this.testEnd id = + testStopWatch.Stop() + let elapsedSeconds = float testStopWatch.ElapsedMilliseconds / 1000. + testTimes.Add(id, elapsedSeconds) - member this.testEnd id = () member this.quit () = () member this.suiteBegin () = () member this.suiteEnd () = ()