I am using DotCoverNUnit in FAKE for code coverage .
It is giving some error
`Starting Target: TestCoverage (==> BuildUnitTest)
./Buildtools/dotCover/dotCover.exe "cover" "/TargetExecutable=./Libs/NUnit.Runners.2.6.3/tools/nunit-console.exe" "/TargetArguments="-nologo" "-labels" "D:\Project\build\project.UnitTest.dll" "-xml:D:\Project\TestResult.xml"" "/Output=./test/NUnitDotCover.xml"
./Buildtools/dotCover/dotCover.exe "cover" "/TargetExecutable=./Libs/NUnit.Runners.2.6.3/tools/nunit-console.exe" "/TargetArguments="-nologo" "-labels" "D:\Project\build\Project.UnitTest.dll" "-xml:D:\Project\TestResult.xml"" "/Output=./test/NUnitDotCover.xml"
JetBrains dotCover Console Runner v2.6.608.684. Copyright (c) 2009–2017 JetBrains s.r.o. All rights reserved.
**Command 'cover' doesn't support 4 unnamed arguments**
Type 'dotCover help' for usage.
Running build failed.
Error:
System.Exception: Error running ./Buildtools/dotCover/dotCover.exe with exitcode -1
at Fake.DotCover.buildParamsAndExecute#124-6.Invoke(String message)
at Fake.DotCover.buildParamsAndExecute[a](a parameters, FSharpFunc2 buildArguments,String toolPath, String workingDir, Boolean failBuild)
at Fake.DotCover.DotCoverNUnit(FSharpFunc 2 setDotCoverParams, FSharpFunc2 setNUnitParams, IEnumerable 1 assemblies)
at FSI_0005.Build.clo#98-8.Invoke(Unit _arg6) in D:\ICIS API develop\icis-api\build.fsx:line 99`
I am not able to figure out the problem out there in this code , I was able to run this code earlier but right now it is not wroking .
Here is the code that I am using for DotCover :
Target "TestCoverage" (fun _ ->
!! (buildDir ## "/Project.UnitTest.dll")
|> DotCoverNUnit
(fun p -> { p with TargetExecutable ="nunit-console.exe"
Output ="NUnitDotCover.xml"
ToolPath = "dotCover.exe"
ErrorLevel = DontFailBuild
Filters = filters })
(fun nunitOptions ->
{ nunitOptions with DisableShadowCopy = true })
tracefn "##teamcity[importData type='dotNetCoverage' tool='dotcover' path='%s']" (testDir ## "NUnitDotCover.xml")
)
Related
I'm working through the Embedding F# Interactive example from here but like this post, I'm having an issue with the following line throwing an exception:
let fsiSession = FsiEvaluationSession.Create(fsiConfig, allArgs, inStream, outStream, errStream)
The exception thrown is:
"System.Exception: 'Error creating evaluation session: StopProcessingExn None'"
My project is being run from VS2017 Enterprise, setup as a simple F# console app, with the Target Framework as .NET Core 2.0. The version of FSharp.Compiler.Service downloaded from nuget is 17.0.1 and FSharp.Core is 4.2.0.
The Program.Fs file code I'm running is here (a direct port of the example):
open System
open System.IO
open System.Text
open Microsoft.FSharp.Compiler.Interactive.Shell
[<EntryPoint>]
let main argv =
let sbOut = new StringBuilder()
let sbErr = new StringBuilder()
let inStream = new StringReader("")
let outStream = new StringWriter(sbOut)
let errStream = new StringWriter(sbErr)
// Build command line arguments & start FSI session
let argv = [| "C:\\Program Files (x86)\\Microsoft SDKs\\F#\\4.1\\Framework\\v4.0\\fsi.exe" |]
let allArgs = Array.append argv [|"--noninteractive"|]
let fsiConfig = FsiEvaluationSession.GetDefaultConfiguration()
let fsiSession = FsiEvaluationSession.Create(fsiConfig, allArgs, inStream, outStream, errStream)
/// Evaluate expression & return the result
let evalExpression text =
match fsiSession.EvalExpression(text) with
| Some value -> printfn "%A" value.ReflectionValue
| None -> printfn "Got no result!"
evalExpression "42+1" // prints '43'
Console.ReadLine() |> ignore
0 // return integer
I already tried to add the files FSharp.Core.optdata and FSharp.Core.sigdata in my bin folder (bin\Debug\netcoreapp2.0) as mentioned here and here, but without success. By the way, my bin folder does not contain the file FSharp.Core.dll.
I also tried to publish my app and add the .optdata and .sigdata files manually in the publish folder, but without success either.
Any thoughts would be appreciated.
I am trying to use dotCover in FAKE .I am getting an error i.e. DotCoverNUnit is not defined .I think this is the problem with the package .
Here is my Code for DotCover in FAKE :
let filters = ""
Target "TestCoverage" (fun _ ->
!! ("D:/Test/Project/Project1/UnitTests/UnitTest.dll")
|> DotCoverNUnit (fun p ->
{ p with
Output = testDir ## "NUnitDotCover.snapshot"
Filters = filters }) nunitOptions
)
Please tell me how to install DotCover in Fake or how to use this . This would be very helpful .
The Fake.DotCover module is not auto-opened, so its functions aren't available until you do open Fake.DotCover near the top of your script.
Unfortunately, the FAKE API documentation currently isn't very good at telling you which modules are auto-opened and which ones need open (modulename) in order to expose their functions.
Update: The way you should be calling DotCoverNUnit is as follows:
let filters = ""
Target "TestCoverage" (fun _ ->
!! ("D:/Test/Project/Project1/UnitTests/UnitTest.dll")
|> DotCoverNUnit
(fun p -> { p with Output = testDir ## "NUnitDotCover.snapshot"
Filters = filters })
(fun nunitOptions -> nunitOptions)
)
Or, if you want to change some of the NUnit options:
let filters = ""
Target "TestCoverage" (fun _ ->
!! ("D:/Test/Project/Project1/UnitTests/UnitTest.dll")
|> DotCoverNUnit
(fun dotCoverOptions ->
{ dotCoverOptions with Output = testDir ## "NUnitDotCover.snapshot"
Filters = filters })
(fun nunitOptions ->
{ nunitOptions with ExcludeCategory = "Manual,LongRunning"
DisableShadowCopy = true })
)
See http://fsharp.github.io/FAKE/apidocs/fake-nunitcommon-nunitparams.html for the complete list of what NUnit options are available from inside FAKE.
I am trying to use DotCover in FAKE , but it is throwing some error , as I am new to FAKE as well as F# , it's becoming difficult for me to understand the root cause of the problem . Here is the code :
#r "D:/FAKEProject/Fake/packages/FAKE/tools/FakeLib.dll"
open Fake
open Fake.DotCover
let testDir = "D:/FAKEProject/Fake/test/"
let filters = ""
Target "Clean" (fun _ ->
CleanDirs [testDir]
)
Target "TestCoverage" (fun _ ->
!! ("D:/FAKEProject/Fake/UnitTest/UnitTest.dll")
|> DotCoverNUnit
(fun p -> { p with Output = testDir ## "NUnitDotCover.snapshot"
ToolPath = "D:/tools/dotCover/dotCover.exe"
Filters = filters })
(fun nunitOptions -> nunitOptions)
)
"Clean"
==> "TestCoverage"
RunTargetOrDefault "TestCoverage"`
It is giving this error
System.Exception: Error running D:/tools/dotCover/dotCover.exe with exitcode -1
at Fake.DotCover.buildParamsAndExecute#124-6.Invoke(String message) in C:\code\fake\src\app\FakeLib\DotCover.fs:line 124
at Fake.DotCover.buildParamsAndExecute[a](a parameters, FSharpFunc`2 buildArguments, String toolPath, String workingDir, Boolean failBuild) in C:\code\fake\src\app\FakeLib\DotCover.fs:line 124
at Fake.DotCover.DotCoverNUnit(FSharpFunc`2 setDotCoverParams, FSharpFunc`2 setNUnitParams, IEnumerable`1 assemblies) in C:\code\fake\src\app\FakeLib\DotCover.fs:line 190
at FSI_0005.DotCover.clo#16-2.Invoke(Unit _arg2) in D:\FAKEProject\Fake\DotCover.fsx:line 17
at Fake.TargetHelper.runSingleTarget(TargetTemplate`1 target) in C:\code\fake\src\app\FakeLib\TargetHelper.fs:line 492`
I am not able to understand why it is searching in C:\code\fake\src\app\fakelib\dotcover.fs
and what is dotcover.fs it is looking for
How to solve this problem , as I am stuck at this error , If anyone can help me regarding this , it would be very helpful .
Thank You
The mysterious C:\code\fake\src\app\FakeLib\DotCover.fs line is simply telling you the filename (and line number) of the source file that threw the error. Not the filename on your system, but the filename on the system where your FAKE.exe file was built. In other words, it's just telling you where the exception was thrown from.
Looking at the FAKE source code, I see that line 124 is near the end of the following block of code:
let buildParamsAndExecute parameters buildArguments toolPath workingDir failBuild =
let args = buildArguments parameters
trace (toolPath + " " + args)
let result = ExecProcess (fun info ->
info.FileName <- toolPath
info.WorkingDirectory <- getWorkingDir workingDir
info.Arguments <- args) TimeSpan.MaxValue
let ExitCodeForFailedTests = -3
if (result = ExitCodeForFailedTests && not failBuild) then
trace (sprintf "DotCover %s exited with errorcode %d" toolPath result)
else if (result = ExitCodeForFailedTests && failBuild) then
failwithf "Failing tests, use ErrorLevel.DontFailBuild to ignore failing tests. Exited %s with errorcode %d" toolPath result
else if (result <> 0) then
failwithf "Error running %s with exitcode %d" toolPath result
else
trace (sprintf "DotCover exited successfully")
The failwithf function is F#'s equivalent of "throw new Exception()", but it lets you specify a message (using printfn-style format codes like %s) to go with the exception. So there's nothing mysterious going on here in F#, it's just that your D:/tools/dotCover/dotCover.exe program has returned a -1 return code. Return codes of -1 usually mean "generic error", so that's not much help in figuring out the cause.
Your next troubleshooting step is to run your dotCover.exe program manually, giving it the same arguments that FAKE is giving it (shouldn't be too hard to figure out, since the FAKE option records are usually pretty well-named) and the same input. Then see what error messages, if any, dotCover.exe is printing out before it fails.
I have a FAKE build script that contains a DotCover coverage step using using the DotCoverNUnit3 extension:
let filters = ""
!! (buildDir ## "/*.UnitTests.dll")
|> DotCoverNUnit3 (fun p ->
{ p with
Output = artifactsDir ## "NUnitDotCover.snapshot"
Filters = filters }) nunitOptions
The snapshot generates correctly, but the coverage overview doesn't appear in the TeamCity build.
I then tried calling DotCoverReport after building the snapshot:
DotCoverReport (fun p ->
{ p with
Source = artifactsDir ## "NUnitDotCover.snapshot"
Output = artifactsDir ## "NUnitDotCover.xml"
ReportType = DotCoverReportType.Xml }) true
This generates the expected XML report, but again, the coverage overview doesn't appear in the build overview page.
As a side note - I'm not sure what the boolean parameter on the end of the DotCoverReport method is, can't find a reference to it on the FAKE docs. I tried switching the value, but it didn't make a difference.
Does anyone know how I can get TeamCity to pickup the DotCover report?
Found a solution.
After drilling down through many layers of TeamCity documentation, I found this page: https://confluence.jetbrains.com/display/TCD9/Manually+Configuring+Reporting+Coverage
Which describes using service messages to point TeamCity in the direction of the snapshot.
So, in the end I didn't need the DotCoverReport, just the snapshot:
For dotCover you should send paths to the snapshot file that is generated by the dotCover.exe cover command.
This is my resulting Target:
let artifactsDir = environVarOrDefault "ARTIFACT_DIR" (currentDirectory ## "artifacts")
let nunitOptions nUnit3Defaults =
{ NUnit3Defaults with
TimeOut = TimeSpan.MaxValue
WorkingDir = artifactsDir }
Target "TestCoverage" (fun _ ->
let filters = ""
!! (buildDir ## "/*.UnitTests.dll")
|> DotCoverNUnit3 (fun p ->
{ p with
Output = artifactsDir ## "NUnitDotCover.snapshot"
Filters = filters }) nunitOptions
tracefn "##teamcity[importData type='dotNetCoverage' tool='dotcover' path='%s']" (artifactsDir ## "NUnitDotCover.snapshot")
)
In my Powershell script (PSAKE), I have the ability to specify the Namespace/Fixture to run when I execute the NUnit test runner.
task UnitTest -Depends Compile -Description "Runs only Unit Tests" {
Invoke-Nunit "$buildOutputDir\$testAssembly.dll" "$testAssembly.Unit" $buildArtifactsDir
}
task IntegrationTest -Depends Compile -Description "Runs only Integration Tests" {
Invoke-Nunit "$buildOutputDir\$testAssembly.dll" "$testAssembly.Integration" $buildArtifactsDir
}
task FunctionalTest -Depends Compile -Description "Runs only Functional Tests" {
Invoke-Nunit "$buildOutputDir\$testAssembly.dll" "$testAssembly.Functional" $buildArtifactsDir
}
This allows me to have three outputs
Unit-TestResults.xml
Integration-TestResults.xml
Functional-TestResults.xml
I'm in the process of switching over to FAKE because it's just so much cleaner to maintain, however I can't figure out how to specify the Fixture for my test.
IE: right now I have
// Run Tests
Target "Tests" (fun _ ->
testDlls
|> NUnit (fun p ->
{p with
DisableShadowCopy = true;
OutputFile = artifactDir + "/TestResults.xml"
})
)
But this runs ALL the tests and drops it into a single output. I'd really like to specify the Fixture, and be able to split it all up. Is there a way to do this?
Newest version of FAKE added support for Fixture parameter. You should be able to do:
Target "Tests" (fun _ ->
testDlls
|> NUnit (fun p ->
{p with
Fixture ="Namespace.Unit"
DisableShadowCopy = true;
OutputFile = artifactDir + "/Unit-TestResults.xml"
})
testDlls
|> NUnit (fun p ->
{p with
Fixture ="Namespace.Integration"
DisableShadowCopy = true;
OutputFile = artifactDir + "/Integration-TestResults.xml"
})
testDlls
|> NUnit (fun p ->
{p with
Fixture ="Namespace.Functional"
DisableShadowCopy = true;
OutputFile = artifactDir + "/Functional-TestResults.xml"
})
)