성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
[정성태] "props[i].GetValue(props[i])" 코드에서 ...
[정성태] 저렇게 조각 코드 말고, 실제로 재현이 되는 예제 프로젝트를 압...
[정성태] Modules 창(Ctrl+Shift+U)을 띄워서, 해당 Op...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <div style='font-family: 맑은 고딕, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>Visual Studio 2010 - Code Coverage 결과를 외부 XML 파일로 출력하는 명령행 도구 제작</div> <br /> Visual Studio 2010에서 Code Coverage를 수행하면 다음과 같이 내부 "Code Coverage Results" 윈도우에서 그 결과를 확인해 볼 수 있는데요.<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='how_to_export_code_coverage_result_1.png' src='/SysWebRes/bbs/how_to_export_code_coverage_result_1.png' /><br /> <br /> 위와 같은 결과물은 로컬 상에 "[파일명].coverage"라는 이름으로 저장되어 있긴 한데, 애석하게도 바이너리 형식이라서 임의로 활용하는 것이 쉽지 않습니다. 물론, 위의 화면 자체에서 제공되는 "Export Results" 버튼을 이용해서 곧바로 XML 파일로 변환해서 보관하는 것이 가능하지만, 자동화된 빌드 시스템에서 코드 커버리지 결과도 함께 연동하고 싶을 때는 이렇게 UI를 통해서 하는 것은 전혀 도움이 되지 않습니다.<br /> <br /> 즉, "명령행"에서 빌드 및 테스트 수행 결과로 생성된 .coverage 파일을 "Export Results"와 동일한 형식의 XML로 변환하는 것이 해결 과제입니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 다행히, Visual Studio는 ".coverage" 파일을 코드로 다룰 수 있도록 허용해 주고 있는데요. 이에 관해서는 다음의 글에서 설명해 주고 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; width: 800px; background-color: #fbedbb; overflow-x: scroll; font-family: Consolas, Verdana;' > Is it possible to programmatically access code coverage data? ; <a target='_tab' href='http://www.go4answers.com/Example/possible-programmatically-access-code-4285.aspx'>http://www.go4answers.com/Example/possible-programmatically-access-code-4285.aspx</a> </pre> <br /> 위의 글에서는 "Visual Studio 2008"로 되어 있지만, 여기서는 "Visual Studio 2010"을 기준으로 설명합니다.<br /> <br /> <div style='font-family: 맑은 고딕, Consolas; font-size: 12pt; color: #2211AA; text-align: left; font-weight: bold'>1. 새 프로젝트를 생성하고, "Microsoft.VisualStudio.Coverage.Analysis.dll"을 참조.</div><br /> <br /> Microsoft.VisualStudio.Coverage.Analysis.dll 파일은 기본적으로 참조 대화상자에 나오지 않기 때문에, "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies" 경로로 직접 찾아들어가야 합니다.<br /> <br /> <div style='font-family: 맑은 고딕, Consolas; font-size: 12pt; color: #2211AA; text-align: left; font-weight: bold'>2. "Microsoft.VisualStudio.Coverage.Symbols.dll" 파일 추가</div><br /> Microsoft.VisualStudio.Coverage.Analysis.dll 파일과 동일한 폴더("C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies")에 있는 "Microsoft.VisualStudio.Coverage.Symbols.dll" 파일을 추가합니다. "참조"가 아니라 그냥 파일 추가를 하고 속성 창에서 다음과 같이 설정을 해줍니다.<br /> <br /> <img alt='how_to_export_code_coverage_result_2.png' src='/SysWebRes/bbs/how_to_export_code_coverage_result_2.png' /><br /> <br /> <div style='BACKGROUND-COLOR: #ccffcc; padding: 10px 10px 5px 10px; width: 700px; MARGIN: 0px 10px 10px 10px; FONT-FAMILY: 맑은 고딕, Consolas, Verdana; COLOR: #005555'> Build Action: None<br /> Copy to Output Directory: <b style='COLOR: blue'>Copy if newer</b><br /> </div><br /> <br /> <div style='font-family: 맑은 고딕, Consolas; font-size: 12pt; color: #2211AA; text-align: left; font-weight: bold'>3. 코드 추가</div><br /> <br /> Visual Studio 2010에서는 "<a target='_tab' href='http://www.go4answers.com/Example/possible-programmatically-access-code-4285.aspx'>Is it possible to programmatically access code coverage data?</a>" 글에서 설명하고 있는 개체 모델이 다소 변경이 되었습니다. 따라서 다음과 같은 식으로 코딩을 해주어야 합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; width: 800px; background-color: #fbedbb; overflow-x: scroll; font-family: Consolas, Verdana;' > using System; using System.Collections.Generic; using System.Linq; using System.Text; <b style='COLOR: blue'>using Microsoft.VisualStudio.Coverage.Analysis;</b> using System.IO; namespace CodeCoverageExporter { class Program { static void Main(string[] args) { if (args.Length != 4) { Console.WriteLine("[example]"); Console.WriteLine("\tCodeCoverageExporter.exe [exepath] [sympath] [coveragefilepath] [outputfilepath]"); return; } string binaryPath = args[0]; string symPath = args[1]; string coverageFilePath = args[2]; string outputPath = args[3]; List<string> symPaths = new List<string>(); List<string> binaryPaths = new List<string>(); symPaths.Add(symPath); binaryPaths.Add(binaryPath); <b style='COLOR: blue'> CoverageInfo coverageInfo = CoverageInfo.CreateFromFile( coverageFilePath, binaryPaths, symPaths); string exportFilePath = Path.Combine(Environment.CurrentDirectory, outputPath); CoverageDS data = coverageInfo.BuildDataSet(); data.WriteXml(exportFilePath); // 또는 결과 XML 파일을 VS IDE에서 읽어들여야 한다면 아래와 같이 실행. // data.WriteXml(exportFilePath, System.Data.XmlWriteMode.WriteSchema); </b> } } } </pre> <br /> [exepath]와 [sympath]는 보통 단위 테스트 했을 때 나오는 "TestResults"의 "Out" 폴더인데요. 예를 들면 다음과 같이 "*.instr.pdb" 파일들이 놓인 경로를 가리켜야 합니다.<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='how_to_export_code_coverage_result_3.png' src='/SysWebRes/bbs/how_to_export_code_coverage_result_3.png' /><br /> <br /> [coveragefilepath]는 코드 커버리지 결과를 담고 있는 "[파일명].coverage"의 경로입니다. 이 파일은 단위 테스트 했을 때 보통 "TestResults"의 "In" 폴더에 "data.coverage"라는 이름으로 놓이게 됩니다.<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='how_to_export_code_coverage_result_4.png' src='/SysWebRes/bbs/how_to_export_code_coverage_result_4.png' /><br /> <br /> 마지막으로 [outputfilepath]는 새로 출력될 XML 파일의 경로를 적어주면 됩니다.<br /> <br /> 이제 빌드하고, 적절한 테스트 환경을 구성해서 실행해 보면 "Visual Studio 2010"의 "Code Coverage Results" 화면에서 "Export Results" 했을 때와 동일한 형식의 xml 파일이 생성되는 것을 확인할 수 있습니다.<br /> <br /> <a target='_tab' href='첨부된 압축 파일은 위의 소스 코드를 포함한 프로젝트'>첨부된 압축 파일은 위의 소스 코드를 포함한 프로젝트</a>입니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 참고로, "<a target='_tab' href='http://www.go4answers.com/Example/possible-programmatically-access-code-4285.aspx'>Is it possible to programmatically access code coverage data?</a>" 글에서도 나오고 있지만, 만약 다음과 같은 오류가 발생한다면,<br /> <br /> <div style='BACKGROUND-COLOR: #ccffcc; padding: 10px 10px 5px 10px; width: 700px; MARGIN: 0px 10px 10px 10px; FONT-FAMILY: 맑은 고딕, Consolas, Verdana; COLOR: #005555'> Unhandled Exception: Microsoft.VisualStudio.Coverage.Analysis.CoverageAnalysisException: Unable to load DLL 'Microsoft.VisualStudio.Coverage.Symbols.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) ---> System.DllNotFoundException: Unable to load DLL 'Microsoft.VisualStudio.Coverage.Symbols.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)<br /> at Microsoft.VisualStudio.Coverage.Analysis.Vsp.SymbolInterop.CreateSession()<br /> at Microsoft.VisualStudio.Coverage.Analysis.Vsp.VspSymbolReader..ctor(StringsymbolSearchPath, String expectedPath, String actualPath, UInt32 imageSize, MissingFileCallback callback)<br /> at Microsoft.VisualStudio.Coverage.Analysis.Vsp.VspSymbolReaderFactory.CreateReader()<br /> at Microsoft.VisualStudio.Coverage.Analysis.CoverageInfo.BuildDataSet(Boolean summaryOnly, IEnumerable`1 tests, IEnumerable`1 modules)<br /> --- End of inner exception stack trace ---<br /> at Microsoft.VisualStudio.Coverage.Analysis.CoverageInfo.BuildDataSet(Boolean summaryOnly, IEnumerable`1 tests, IEnumerable`1 modules)<br /> at Microsoft.VisualStudio.Coverage.Analysis.CoverageInfo.BuildDataSet()<br /> at CodeCoverageExporter.Program.Main(String[] args) in D:\...\Program.cs:line 37<br /> </div><br /> <br /> 원인은, "Microsoft.VisualStudio.Coverage.Symbols.dll" 파일을 실행 파일과 동일한 폴더에 놓지 않아서 발생하는 것입니다.<br /> <br /><br /><hr /><span style='color: Maroon'>[이 토픽에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
2065
(왼쪽의 숫자를 입력해야 합니다.)