Skip to content

Instantly share code, notes, and snippets.

@Steinblock
Last active November 9, 2016 10:55
Show Gist options
  • Save Steinblock/2dd24006dab11d70fb5c4fccd03ad8c4 to your computer and use it in GitHub Desktop.
Save Steinblock/2dd24006dab11d70fb5c4fccd03ad8c4 to your computer and use it in GitHub Desktop.
Example FAKE script to run all test at once
let artifactsDir = "./.ci/artifacts/"
/// modified versions of buildMSTestArgs wich adds testcontainer arguments for multiple assembiles https://github.com/fsharp/FAKE/blob/master/src/app/FakeLib/UnitTest/MSTest.fs
let buildMSTestArgs2 parameters (assemblies : string seq) =
// https://msdn.microsoft.com/de-de/library/ms182489.aspx#detail
let detail_errormessage = "errormessage"
let detail_errorstacktrace = "errorstacktrace"
let detail_duration = "duration"
// TODO: assemblies should be quoted each
let testcontainers = assemblies |> separated " /testcontainer:"
let testResultsFile =
if parameters.ResultsDir <> null && parameters.ResultsDir.EndsWith(".trx", StringComparison.OrdinalIgnoreCase) = false then
sprintf @"%s\%s.trx" parameters.ResultsDir (DateTime.Now.ToString("yyyyMMdd-HHmmss.ff"))
else
DeleteFile parameters.ResultsDir // delete file if exist
parameters.ResultsDir
new System.Text.StringBuilder()
|> appendWithoutQuotesIfNotNull testcontainers "/testcontainer:"
|> appendIfNotNull parameters.Category "/category:"
|> appendIfNotNull parameters.TestMetadataPath "/testmetadata:"
|> appendIfNotNull parameters.TestSettingsPath "/testsettings:"
|> appendIfNotNull testResultsFile "/resultsfile:"
|> appendIfTrue parameters.NoIsolation "/noisolation"
|> appendIfNotNull detail_errormessage "/detail:"
|> appendIfNotNull detail_errorstacktrace "/detail:"
|> appendIfNotNull detail_duration "/detail:"
|> toText
/// modified versions of MSTest wich executes all tests at once https://github.com/fsharp/FAKE/blob/master/src/app/FakeLib/UnitTest/MSTest.fs
let MSTest2 (setParams : MSTestParams -> MSTestParams) (assemblies : string seq) =
let details = assemblies |> separated ", "
traceStartTask "MSTest" details
let parameters = MSTestDefaults |> setParams
let assemblies = assemblies |> Seq.toArray
if Array.isEmpty assemblies then failwith "MSTest: cannot run tests (the assembly list is empty)."
let failIfError assembly exitCode =
if exitCode > 0 && parameters.ErrorLevel <> ErrorLevel.DontFailBuild then
let message = sprintf "%sMSTest test run failed for %s" Environment.NewLine assembly
traceError message
failwith message
let args = buildMSTestArgs2 parameters assemblies
ExecProcess (fun info ->
info.FileName <- parameters.ToolPath
info.WorkingDirectory <- parameters.WorkingDir
info.Arguments <- args) parameters.TimeOut
|> failIfError "Test failed"
traceEndTask "MSTest" details
Target "Test" (fun _ ->
trace "Test..."
!! "Tests/**/bin/**/*.Tests.dll"
|> MSTest2 (fun p ->
{ p with
Category = "!excel"
ResultsDir = artifactsDir + "TestResults.trx"
ErrorLevel = ErrorLevel.Error
TestSettingsPath = testSettingsPath
NoIsolation = false
TimeOut = TimeSpan.FromMinutes 15.
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment