성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
[정성태] "props[i].GetValue(props[i])" 코드에서 ...
[정성태] 저렇게 조각 코드 말고, 실제로 재현이 되는 예제 프로젝트를 압...
[정성태] Modules 창(Ctrl+Shift+U)을 띄워서, 해당 Op...
[정성태] 만드실 수 있습니다. 단지, Unity 엔진 내의 스크립트와 W...
[공진영] 안녕하세요 좋은글 감사합니다. 현재 제가 wpf로 관제 모...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>C# Code Coverage 도구 - Semantic Designs 소개</h1> <p> 오늘은 code coverage 도구 하나 소개합니다. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Semantic Designs - Test Coverage tools ; <a target='tab' href='http://www.semdesigns.com/Products/TestCoverage/'>http://www.semdesigns.com/Products/TestCoverage/</a> </pre> <br /> 여러 가지를 지원하는 데 그 중에 C#도 지원합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C# Test Coverage Tool ; <a target='tab' href='http://www.semdesigns.com/Products/TestCoverage/CSharpTestCoverage.html?Home=TestCoverage'>http://www.semdesigns.com/Products/TestCoverage/CSharpTestCoverage.html?Home=TestCoverage</a> </pre> <br /> 평가판 받기를 시도하면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Download an evaluation copy ; <a target='tab' href='http://www.semdesigns.com/Products/RegisterEval.html?Domain=CSharp&Dialect=CSharp4_0&Product=TestCoverage'>http://www.semdesigns.com/Products/RegisterEval.html?Domain=CSharp&Dialect=CSharp4_0&Product=TestCoverage</a> </pre> <br /> 약간의 등록 정보를 받는 페이지로 이동하고 거기에 이메일 주소를 입력하면 평가판 설치 파일을 다운로드 받을 수 있는 메일이 오고, 그 링크를 클릭해 설치하면 됩니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 설치를 마치면, code-coverage 용 예제 프로젝트가 있는데 그걸로 한번 진행해 보겠습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\Program Files (x86)\SemanticDesigns\DMS\Domains\CSharp\CSharp4_0\Tools\TestCoverage\Example </pre> <br /> cmd.exe 창을 띄우고, 위의 폴더로 이동한 다음 RunExample.cmd를 실행합니다. 그럼, 화면에 동작 원리를 추측할 수 있는 로그가 출력되는데요. 조금씩 볼까요? ^^<br /> <br /> 첫 실행 후 우선 C# 컴파일러를 찾습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\Program Files (x86)\SemanticDesigns\DMS\Domains\CSharp\CSharp4_0\Tools\TestCoverage\Example><span style='color: blue; font-weight: bold'>RunExample.cmd</span> Runexample.cmd V2.1.4: Run DMS C# Test Coverage Tool Suite example. Copyright (C) 2003-2011 Semantic Designs; All Rights Reserved <span style='color: blue; font-weight: bold'>Found CSharp compiler</span> (csc.exe) at C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe </pre> <br /> 이어서 code-coverage할 소스 코드를,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > *** Copying example files to a temp directory *** The system cannot find the path specified. 1 file(s) copied. <span style='color: blue; font-weight: bold'>C:\Program Files (x86)\SemanticDesigns\DMS\Domains\CSharp\CSharp4_0\Tools\TestCoverage\Example\Source\AnotherSwitch.cs C:\Program Files (x86)\SemanticDesigns\DMS\Domains\CSharp\CSharp4_0\Tools\TestCoverage\Example\Source\SwitchCases.cs 2 file(s) copied. </span> *** Installing test coverage probes Copyright (C) 2002-2005 Semantic Designs; All Rights Reserved CSharp~CSharp4_0 TestCoverage Probe Installer Version 1.2.29 Copyright (C) 2004-2013 Semantic Designs, Inc; All Rights Reserved; SD Confidential Powered by DMS (R) Software Reengineering Toolkit *** Unregistered TestCoverage Version 1.2 *** Operating with evaluation limits. </pre> <br /> /Target 임시 폴더에 복사하겠죠? ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > This evaluation version handles up to 3 files, each of up to 1000 lines of source code. The -increment and -validate options are ignored in this evaluation version. Project file successfully read: Incremental probe insertion: ~f Probe reference file: SwitchCases.prf Source file input directory prefix: c:/Users/...[계정].../AppData/Local/Temp/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/Source <span style='color: blue; font-weight: bold'>Target file output directory prefix: c:/Users/...[계정].../AppData/Local/Temp/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/Target</span> Directory-resolved source file names: c:/Users/...[계정].../AppData/Local/Temp/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/Source/SwitchCases.cs c:/Users/...[계정].../AppData/Local/Temp/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/Source/AnotherSwitch.cs </pre> <br /> 소스 코드 파일을 파싱해서, 의미가 있는 소스 코드 단계마다 coverage 코드를 추가해 C# 파일을 새롭게 저장합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Parsing source file "c:/Users/...[계정].../AppData/Local/Temp/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/Source/SwitchCases.cs" ... Installing test coverage probes ... Registry: Loading RSL definitions from "C:/Program Files (x86)/SemanticDesigns/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/TestCoverage.rsl" ... Registry: Successfully loaded RSL definitions from "C:/Program Files (x86)/SemanticDesigns/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/TestCoverage.rsl". <span style='color: blue; font-weight: bold'>Writing target file "c:/Users/...[계정].../AppData/Local/Temp/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/Target/SwitchCases.cs"</span> ... Parsing source file "c:/Users/...[계정].../AppData/Local/Temp/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/Source/AnotherSwitch.cs" ... Installing test coverage probes ... <span style='color: blue; font-weight: bold'>Writing target file "c:/Users/...[계정].../AppData/Local/Temp/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/Target/AnotherSwitch.cs"</span> ... Creating test coverage vector configuration file "c:/Users/...[계정].../AppData/Local/Temp/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/Target/TCVConfiguration.cs" ... Creating probe reference file "c:/Users/...[계정].../AppData/Local/Temp/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/Target/SwitchCases.prf" ... Exiting with final status 0. </pre> <br /> 변경된 소스 코드파일을 첫 단계에서 찾아냈던 C# 컴파일러를 이용해 빌드 후 실행시켜줍니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > *** Compiling sources with test coverage probes Microsoft (R) Visual C# Compiler version 4.0.30319.34209 for Microsoft (R) .NET Framework 4.5 Copyright (C) Microsoft Corporation. All rights reserved. *** Executing test cases *** Executing "SwitchCases 4" case 4 Writing Test Coverage Vector "%SwitchCases4_2015_03_07_16_53_15_184.tcv" ... Dumped Test Coverage Vector of one execution to file : %SwitchCases4_2015_03_07_16_53_15_184.tcv *** Executing "SwitchCases 9" case 9 Argument greater than 5 another case 9 Writing Test Coverage Vector "%SwitchCases9_2015_03_07_16_53_15_213.tcv" ... Dumped Test Coverage Vector of one execution to file : %SwitchCases9_2015_03_07_16_53_15_213.tcv *** Invoking test coverage display TCVDisplay.cmd: DMS Test Coverage Vector Display. Copyright (C) 2001-2012 Semantic Designs; All Rights Reserved Test Coverage Vector Display Tool, Version 1.2.26 Copyright (c) Semantic Designs 2001-2012; All Rights Reserved; SD Confidential Constructing source files tree ... Done. </pre> <br /> 그리곤 마지막으로 이 창이 뜹니다.<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='code-coverage_semantic-designs_1.png' src='/SysWebRes/bbs/code-coverage_semantic-designs_1.png' /><br /> <br /> 좌측을 보면, 개별 소스 코드 파일 목록이 나오고 그 각각의 하위에 소스 코드에 Semantic Designs 도구에서 넣어둔 코드 지점마다 코드 커버리지 구역을 나열해 주고 있습니다. 또한 하단의 표시줄에 보면 "AnotherSwitch.cs" 파일의 경우 "Probes in File: 28"이라고 해서 Probe 지점이 총 28개임을 나타내주고, "Covered: 0(0.0%)"라고 해당 소스 코드의 커버리지가 전무함을 볼 수 있습니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 그러니까, "Semantic Designs" 제품은 개발 소스 코드를 입력으로 받아서 미리 if 문등의 분기지점마다 "Semantic Designs" 제품 특유의 소스 코드를 넣어둡니다. 그렇게 변경된 파일을 컴파일 해서 최종 EXE를 만든 후 임시 폴더에 실행 파일을 저장하고 (예제의 경우, "C:\Users\...[사용자계정]...\AppData\Local\Temp\DMS\Domains\CSharp\CSharp4_0\Tools\TestCoverage\SwitchCases.exe") 그것을 실행합니다.<br /> <br /> 실제로 .NET Reflector를 이용해 SwitchCases.exe 파일을 조사해 보면, 아래의 굵은 코드들이 모두 "Semantic Designs" 제품에서 변형한 소스 코드들임을 알 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > public static void Main(string[] args) { <span style='color: blue; font-weight: bold'>TCV.visited[0x15] = true;</span> if (args.Length < 1) { <span style='color: blue; font-weight: bold'>TCV.visited[20] = true;</span> Console.WriteLine("One integer argument is required to run this example. For example,"); <span style='color: blue; font-weight: bold'>TCV.visited[0x1a] = true;</span> Console.WriteLine(" SwitchCases 4\n"); <span style='color: blue; font-weight: bold'>TCV.visited[0x1b] = true;</span> <span style='color: blue; font-weight: bold'>TCV.dump();</span> } else { int num; <span style='color: blue; font-weight: bold'>TCV.visited[0x1c] = true;</span> try { num = Convert.ToInt32(args[0]); } catch (ArgumentNullException) { <span style='color: blue; font-weight: bold'>TCV.visited[0x13] = true;</span> Console.WriteLine("The argument is null."); <span style='color: blue; font-weight: bold'>TCV.visited[0x1d] = true; TCV.dump();</span> return; } catch (FormatException) { <span style='color: blue; font-weight: bold'>TCV.visited[0x12] = true;</span> Console.WriteLine("String is not a valid number format: an optional sign followed by a series of decimal digits."); <span style='color: blue; font-weight: bold'>TCV.visited[30] = true; TCV.dump();</span> return; } catch (OverflowException) { <span style='color: blue; font-weight: bold'>TCV.visited[0x11] = true;</span> Console.WriteLine("Overflow in String to Int32 conversion for the first argument."); <span style='color: blue; font-weight: bold'>TCV.visited[0x1f] = true; TCV.dump();</span> return; } <span style='color: blue; font-weight: bold'>TCV.visited[0x20] = true;</span> setBaseName("SwitchCases" + num); <span style='color: blue; font-weight: bold'>TCV.visited[0x2e] = true;</span> switch (num) { case 1: <span style='color: blue; font-weight: bold'>TCV.visited[0x10] = true;</span> Console.WriteLine("case 1"); <span style='color: blue; font-weight: bold'>TCV.visited[0x21] = true;</span> break; // ...[생략]... default: <span style='color: blue; font-weight: bold'>TCV.visited[2] = true;</span> Console.WriteLine("case others"); <span style='color: blue; font-weight: bold'>TCV.visited[0x2d] = true;</span> break; } <span style='color: blue; font-weight: bold'>TCV.visited[0x31] = true;</span> if (num > 5) { <span style='color: blue; font-weight: bold'>TCV.visited[1] = true;</span> Console.WriteLine("Argument greater than 5"); <span style='color: blue; font-weight: bold'>TCV.visited[0x2f] = true;</span> AnotherSwitch switch2 = new AnotherSwitch(num); <span style='color: blue; font-weight: bold'>TCV.visited[0x30] = true;</span> switch2.switchAgain(); } <span style='color: blue; font-weight: bold'>TCV.dump();</span> } } </pre> <br /> 대체로 Code-Coverage 툴들이 이런 전처리 과정을 거칩니다. ^^<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1363
(왼쪽의 숫자를 입력해야 합니다.)