Convert MSTest code covarage results in to XML

僤鯓⒐⒋嵵緔 提交于 2019-12-24 00:07:32

问题


I am using this code to convert MSTest code covarage results to XML format , I added reference to Microsoft.VisualStudio.Coverage.Analysis.dll bu there is no class called CoverageInfoManager . I am using VS 2010.

 static void Main(string[] args)
        {
            String coveragepath = System.IO.Path.GetDirectoryName(args[0]);
            CoverageInfoManager.SymPath = coveragepath;
            CoverageInfoManager.ExePath = coveragepath;

            // Create a coverage info object from the file
            String coveragefile = System.IO.Path.GetFullPath(args[1]);
            CoverageInfo ci = CoverageInfoManager.CreateInfoFromFile(coveragefile);



            // Ask for the DataSet.  The parameter must be null
            CoverageDS data = ci.BuildDataSet(null);



            // Write to XML
            String coverageoutput = System.IO.Path.GetFullPath(args[2]);
            data.WriteXml(coverageoutput);

        }

If I use this code instead of above,

 CoverageInfo coverage = CoverageInfo.CreateFromFile(@"....\data.coverage");

it throws an error saying "Image file "...\bin\Debug\TestProject1.dll" could not be found"


回答1:


You need to use a new method to access your coverage file. This will get you there I'm sure:

http://blogs.msdn.com/b/phuene/archive/2009/12/01/programmatic-coverage-analysis-in-visual-studio-2010.aspx




回答2:


I had the same problem, I needed to convert the coverage file to coveragexml by command line.

You might want to use the CoverageInfo and CoverageDS objects as depicted on snip2code.

using (CoverageInfo info = CoverageInfo.CreateFromFile(coverageFileName, new string[] { dllFileName }, new string[] { }))
        {
            CoverageDS data = info.BuildDataSet();

            data.WriteXml(coverageXmlFileName);
        }

Link: How to programmatically convert the Visual Studio coverage file to coveragexml by command line tool in csharp




回答3:


You can find a tool that does the conversion to clover and to html format

The code is located at github.

This tool also uses a xsl transformation to create the html report.



来源:https://stackoverflow.com/questions/6288414/convert-mstest-code-covarage-results-in-to-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!