Dotcover test coverage from a rake task

I'm building a rake task to manually get coverage into TeamCity using xUnit tests

http://confluence.jetbrains.com/display/TCD6/Manually+Configuring+Reporting+Coverage

I'm having some issues getting dotcover to work under an albacore exec rake task using relative paths from my rake file


@xUnitRunnerPath = Pathname.new('../../Tools/xUnit/xunitcontrib-dotcover.2.0/xunit.runner.utility.dll').realpath
@myTestDll = 'C:\PathToProj\My.Project.Tests\bin\Release\My.project.Tests.dll'
@outputDir = 'C:\PathToTestResults\'

exec :testCoverage do |cmd|
    cmd.command = "C:/BuildAgent/tools/dotCover/dotCover.exe"
    cmd.parameters = [
        "cover",
        "/targetexecutable=$$#{@xUnitRunnerPath}$$",
        "/targetarguments=$$#{@myTestDll}$$",
        "/output=#{@outputDir}/My.Project.Tests.dll.dcvr"
    ]
end

The error is unhelpful just telling me paths are wrong

Failed to convert relative paths to absolute in parameters for the 'cover' 
command. The given path's format is not supported. 
Type 'dotCover help' for usage.

This doesn't provide much help and doesn't give many clues as to what's going wrong or why.

Maybe I'm missing the relevant documentation here but it would be really helpful to be able to get this working.



http://devnet.jetbrains.com/thread/439535
This provided a little help as well
2 comments

Hello Neil,

You shouldn't use "$$" symbols in the

/targetexecutable and /targetarguments parameters. Please use escaped double quotes instead of them if your paths contain spaces or nothing if they don't:


cmd.parameters = [

     "cover",

     "/targetexecutable=\"#{@xUnitRunnerPath}\"",

     "/targetarguments=#{@myTestDll}",

     "/output=#{@outputDir}/My.Project.Tests.dll.dcvr"

]

Please let me know whether it helps. Best regards.
0

Thanks, I just got it working this morning, here's the rake tasks to help out anyone with similar problems



#------------------------------------------------------------------------------------------
# Coverage start
#------------------------------------------------------------------------------------------
task :unitTestsWithCoverage do
    @unitTestAssemblies.each do |testAssembly|
        Rake::Task[:unitTestWithCoverage].execute( testAssembly )
        Rake::Task[:coverageServiceMessage].execute( testAssembly )
    end
end


exec :unitTestWithCoverage, [:testAssembly] do |cmd, testAssembly|
    testAssemblyRealPath = Pathname.new(testAssembly).realpath
    testAssemblyName = File.basename(testAssemblyRealPath)


    cmd.command = @dotCoverRealPath
    cmd.parameters = [
        "cover",
        "/AnalyseTargetArguments=False",
        "/TargetExecutable=#{@xUnitRunnerRealPath}",
        "/TargetArguments=#{testAssemblyRealPath}",
        "/Output=#{@testResultsRealPath}/#{testAssemblyName}.dcvr"
    ]
end


task :coverageServiceMessage, [:testAssembly] do |t, testAssembly|
    testAssemblyRealPath = Pathname.new(testAssembly).realpath
    testAssemblyName = File.basename(testAssemblyRealPath)
    puts "##teamcity[importData type='dotNetCoverage' tool='dotcover' path='#{@testResultsRealPath}/#{testAssemblyName}.dcvr']"
end
#------------------------------------------------------------------------------------------
# Coverage end
#------------------------------------------------------------------------------------------

0

Please sign in to leave a comment.