2013-11-27 116 views
1

在我的单元测试项目的生成后事件我跑OpenCover和ReportGenerator得到一个代码覆盖率报告:打开生成生成后事件HTML报告

del "$(SolutionDir)TestResults\Coverage\*.*" 

"$(SolutionDir)packages\OpenCover.4.5.1923\OpenCover.Console.exe" 
-register:user 
-target:"$(MSBuildProgramFiles32)\Microsoft Visual Studio 12.0\ 
    Common7\IDE\MSTest.exe" 
-targetdir:"$(ProjectDir)bin\$(ConfigurationName)" 
-targetargs:"/testcontainer:\"$(TargetPath)\"" 
-output:"$(SolutionDir)TestResults\Coverage\coverage.xml" 
-filter:"+[MyProject]* " 

$(SolutionDir)packages\ReportGenerator.1.9.1.0\ReportGenerator.exe" 
-reports:"$(SolutionDir)TestResults\Coverage\coverage.xml" 
-targetdir:"$(SolutionDir)TestResults\Coverage" 

call "$(SolutionDir)TestResults\Coverage\index.htm" 

的最后一步是打开生成的HTML报告。使用当前的call命令,它将在我的默认Web浏览器中打开HTML报告。但是,如果报告可以在Visual Studio中打开,我希望它。

如果和我将如何实现这一目标?

+0

你能解释一下你希望通过报告对外开放在Visual Studio中,而不是在浏览器中实现什么? –

+0

真的很方便。当我构建我的项目并完成时,它将在同一个窗口中显示构建结果和覆盖率报告,而不是在VS和浏览器之间切换。 –

回答

3

我实际上已经在VS核心自动包装中使用PowerShell和Navigate方法工作,EnvDTE。 我取代了过去的call命令如下:

powershell 
-ExecutionPolicy Unrestricted 
-Command "& { $dte = [System.Runtime.InteropServices.Marshal]:: 
        GetActiveObject(\"VisualStudio.DTE.11.0\"); 
       $dte.ItemOperations.Navigate(
        \"$(SolutionDir)TestResults\Coverage\index.htm\"); }" 

并在打开的VS项目中一个新的浏览器标签页的报告。

+0

作为一个供参考的人与Visual Studio Express的(Web开发)尝试这个,用'VWDExpress.DTE.11.0'替换'VisualStudio.DTE.11.0'。 –

0

您可能能够使用devenv的使用command line开关打开该文件。

devenv /edit $(SolutionDir)TestResults\Coverage\index.htm 

但它可能会打开它作为文件编辑而不是查看。

+0

你最近的评论是正确的,它确实在编辑模式下打开文件,而不是浏览模式。 –

+0

这给出了编辑模式,而不是查看模式。另外如果你在post build事件中运行devenv,你会得到'退出代码9009'的消息。 – hardywang

1

很简单的事情为我工作在岗位建立事件 -

start http://localhost/MYWeb/Home.aspx