Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 260. C# Code Coverage 도구 - Semantic Designs 소개 [링크 복사], [링크+제목 복사],
조회: 15207
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

C# Code Coverage 도구 - Semantic Designs 소개

오늘은 code coverage 도구 하나 소개합니다. ^^

Semantic Designs - Test Coverage tools
; http://www.semdesigns.com/Products/TestCoverage/

여러 가지를 지원하는 데 그 중에 C#도 지원합니다.

C# Test Coverage Tool
; http://www.semdesigns.com/Products/TestCoverage/CSharpTestCoverage.html?Home=TestCoverage

평가판 받기를 시도하면,

Download an evaluation copy 
; http://www.semdesigns.com/Products/RegisterEval.html?Domain=CSharp&Dialect=CSharp4_0&Product=TestCoverage

약간의 등록 정보를 받는 페이지로 이동하고 거기에 이메일 주소를 입력하면 평가판 설치 파일을 다운로드 받을 수 있는 메일이 오고, 그 링크를 클릭해 설치하면 됩니다.




설치를 마치면, code-coverage 용 예제 프로젝트가 있는데 그걸로 한번 진행해 보겠습니다.

C:\Program Files (x86)\SemanticDesigns\DMS\Domains\CSharp\CSharp4_0\Tools\TestCoverage\Example

cmd.exe 창을 띄우고, 위의 폴더로 이동한 다음 RunExample.cmd를 실행합니다. 그럼, 화면에 동작 원리를 추측할 수 있는 로그가 출력되는데요. 조금씩 볼까요? ^^

첫 실행 후 우선 C# 컴파일러를 찾습니다.

C:\Program Files (x86)\SemanticDesigns\DMS\Domains\CSharp\CSharp4_0\Tools\TestCoverage\Example>RunExample.cmd
Runexample.cmd V2.1.4: Run DMS C# Test Coverage Tool Suite example.
Copyright (C) 2003-2011 Semantic Designs; All Rights Reserved
Found CSharp compiler (csc.exe) at C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe

이어서 code-coverage할 소스 코드를,

*** Copying example files to a temp directory ***
The system cannot find the path specified.
        1 file(s) copied.
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.

*** 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.

/Target 임시 폴더에 복사하겠죠? ^^

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
  Target file output directory prefix: c:/Users/...[계정].../AppData/Local/Temp/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/Target
  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

소스 코드 파일을 파싱해서, 의미가 있는 소스 코드 단계마다 coverage 코드를 추가해 C# 파일을 새롭게 저장합니다.

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".
Writing target file "c:/Users/...[계정].../AppData/Local/Temp/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/Target/SwitchCases.cs" ...
Parsing source file "c:/Users/...[계정].../AppData/Local/Temp/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/Source/AnotherSwitch.cs" ...
Installing test coverage probes ...
Writing target file "c:/Users/...[계정].../AppData/Local/Temp/DMS/Domains/CSharp/CSharp4_0/Tools/TestCoverage/Target/AnotherSwitch.cs" ...
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.

변경된 소스 코드파일을 첫 단계에서 찾아냈던 C# 컴파일러를 이용해 빌드 후 실행시켜줍니다.

*** 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.

그리곤 마지막으로 이 창이 뜹니다.

code-coverage_semantic-designs_1.png

좌측을 보면, 개별 소스 코드 파일 목록이 나오고 그 각각의 하위에 소스 코드에 Semantic Designs 도구에서 넣어둔 코드 지점마다 코드 커버리지 구역을 나열해 주고 있습니다. 또한 하단의 표시줄에 보면 "AnotherSwitch.cs" 파일의 경우 "Probes in File: 28"이라고 해서 Probe 지점이 총 28개임을 나타내주고, "Covered: 0(0.0%)"라고 해당 소스 코드의 커버리지가 전무함을 볼 수 있습니다.




그러니까, "Semantic Designs" 제품은 개발 소스 코드를 입력으로 받아서 미리 if 문등의 분기지점마다 "Semantic Designs" 제품 특유의 소스 코드를 넣어둡니다. 그렇게 변경된 파일을 컴파일 해서 최종 EXE를 만든 후 임시 폴더에 실행 파일을 저장하고 (예제의 경우, "C:\Users\...[사용자계정]...\AppData\Local\Temp\DMS\Domains\CSharp\CSharp4_0\Tools\TestCoverage\SwitchCases.exe") 그것을 실행합니다.

실제로 .NET Reflector를 이용해 SwitchCases.exe 파일을 조사해 보면, 아래의 굵은 코드들이 모두 "Semantic Designs" 제품에서 변형한 소스 코드들임을 알 수 있습니다.


public static void Main(string[] args)
{
    TCV.visited[0x15] = true;
    if (args.Length < 1)
    {
        TCV.visited[20] = true;
        Console.WriteLine("One integer argument is required to run this example. For example,");
        TCV.visited[0x1a] = true;
        Console.WriteLine("     SwitchCases 4\n");
        TCV.visited[0x1b] = true;
        TCV.dump();
    }
    else
    {
        int num;
        TCV.visited[0x1c] = true;
        try
        {
            num = Convert.ToInt32(args[0]);
        }
        catch (ArgumentNullException)
        {
            TCV.visited[0x13] = true;
            Console.WriteLine("The argument is null.");
            TCV.visited[0x1d] = true;
            TCV.dump();
            return;
        }
        catch (FormatException)
        {
            TCV.visited[0x12] = true;
            Console.WriteLine("String is not a valid number format: an optional sign followed by a series of decimal digits.");
            TCV.visited[30] = true;
            TCV.dump();
            return;
        }
        catch (OverflowException)
        {
            TCV.visited[0x11] = true;
            Console.WriteLine("Overflow in String to Int32 conversion for the first argument.");
            TCV.visited[0x1f] = true;
            TCV.dump();
            return;
        }
        TCV.visited[0x20] = true;
        setBaseName("SwitchCases" + num);
        TCV.visited[0x2e] = true;
        switch (num)
        {
            case 1:
                TCV.visited[0x10] = true;
                Console.WriteLine("case 1");
                TCV.visited[0x21] = true;
                break;

            // ...[생략]...

            default:
                TCV.visited[2] = true;
                Console.WriteLine("case others");
                TCV.visited[0x2d] = true;
                break;
        }
        TCV.visited[0x31] = true;
        if (num > 5)
        {
            TCV.visited[1] = true;
            Console.WriteLine("Argument greater than 5");
            TCV.visited[0x2f] = true;
            AnotherSwitch switch2 = new AnotherSwitch(num);
            TCV.visited[0x30] = true;
            switch2.switchAgain();
        }
        TCV.dump();
    }
}

대체로 Code-Coverage 툴들이 이런 전처리 과정을 거칩니다. ^^




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 3/7/2015]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 16  17  18  19  20  21  22  23  24  [25]  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13017정성태3/28/20227070.NET Framework: 1184. C# - GC Heap에 위치한 참조 개체의 주소를 알아내는 방법 - 두 번째 이야기 [3]
13016정성태3/27/20228006.NET Framework: 1183. C# 11에 추가된 ref 필드의 (우회) 구현 방법파일 다운로드1
13015정성태3/26/20229259.NET Framework: 1182. C# 11 - ref struct에 ref 필드를 허용 [1]
13014정성태3/23/20227839VC++: 155. CComPtr/CComQIPtr과 Conformance mode 옵션의 충돌 [1]
13013정성태3/22/20226105개발 환경 구성: 641. WSL 우분투 인스턴스에 파이썬 2.7 개발 환경 구성하는 방법
13012정성태3/21/20225448오류 유형: 803. C# - Local '...' or its members cannot have their address taken and be used inside an anonymous method or lambda expression
13011정성태3/21/20226982오류 유형: 802. 윈도우 운영체제에서 웹캠 카메라 인식이 안 되는 경우
13010정성태3/21/20225871오류 유형: 801. Oracle.ManagedDataAccess.Core - GetTypes 호출 시 "Could not load file or assembly 'System.DirectoryServices.Protocols...'" 오류
13009정성태3/20/20227526개발 환경 구성: 640. docker - ibmcom/db2 컨테이너 실행
13008정성태3/19/20226827VS.NET IDE: 176. 비주얼 스튜디오 - 솔루션 탐색기에서 프로젝트를 선택할 때 csproj 파일이 열리지 않도록 만드는 방법
13007정성태3/18/20226386.NET Framework: 1181. C# - Oracle.ManagedDataAccess의 Pool 및 그것의 연결 개체 수를 알아내는 방법파일 다운로드1
13006정성태3/17/20227527.NET Framework: 1180. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 remuxing.c 예제 포팅
13005정성태3/17/20226327오류 유형: 800. C# - System.InvalidOperationException: Late bound operations cannot be performed on fields with types for which Type.ContainsGenericParameters is true.
13004정성태3/16/20226306디버깅 기술: 182. windbg - 닷넷 메모리 덤프에서 AppDomain에 걸친 정적(static) 필드 값을 조사하는 방법
13003정성태3/15/20226452.NET Framework: 1179. C# - (.NET Framework를 위한) Oracle.ManagedDataAccess 패키지의 성능 카운터 설정 방법
13002정성태3/14/20227272.NET Framework: 1178. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 http_multiclient.c 예제 포팅
13001정성태3/13/20227644.NET Framework: 1177. C# - 닷넷에서 허용하는 메서드의 매개변수와 호출 인자의 최대 수
13000정성태3/12/20227242.NET Framework: 1176. C# - Oracle.ManagedDataAccess.Core의 성능 카운터 설정 방법
12999정성태3/10/20226771.NET Framework: 1175. Visual Studio - 프로젝트 또는 솔루션의 Clean 작업 시 응용 프로그램에서 생성한 파일을 함께 삭제파일 다운로드1
12998정성태3/10/20226298.NET Framework: 1174. C# - ELEMENT_TYPE_FNPTR 유형의 사용 예
12997정성태3/10/202210795오류 유형: 799. Oracle.ManagedDataAccess - "ORA-01882: timezone region not found" 오류가 발생하는 이유
12996정성태3/9/202215806VS.NET IDE: 175. Visual Studio - 인텔리센스에서 오버로드 메서드를 키보드로 선택하는 방법
12995정성태3/8/20228187.NET Framework: 1173. .NET에서 Producer/Consumer를 구현한 BlockingCollection<T>
12994정성태3/8/20227467오류 유형: 798. WinDbg - Failed to load data access module, 0x80004002
12993정성태3/4/20227307.NET Framework: 1172. .NET에서 Producer/Consumer를 구현하는 기초 인터페이스 - IProducerConsumerCollection<T>
12992정성태3/3/20228790.NET Framework: 1171. C# - BouncyCastle을 사용한 암호화/복호화 예제파일 다운로드1
... 16  17  18  19  20  21  22  23  24  [25]  26  27  28  29  30  ...