Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 260. C# Code Coverage 도구 - Semantic Designs 소개 [링크 복사], [링크+제목 복사],
조회: 15073
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




1  2  [3]  4  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13562정성태2/21/20241984오류 유형: 896. ASP.NET - .NET Framework 기본 예제에서 System.Web에 대한 System.IO.FileNotFoundException 예외 발생
13561정성태2/20/20242063닷넷: 2218. C# - (예를 들어, Socket) 비동기 I/O에 대한 await 호출 시 CancellationToken을 이용한 취소파일 다운로드1
13560정성태2/19/20242094디버깅 기술: 195. windbg 분석 사례 - Semaphore 잠금으로 인한 Hang 현상 (닷넷)
13559정성태2/19/20242944오류 유형: 895. ASP.NET - System.Security.SecurityException: 'Requested registry access is not allowed.'
13558정성태2/18/20242179닷넷: 2217. C# - 최댓값이 1인 SemaphoreSlim 보다 Mutex 또는 lock(obj)를 선택하는 것이 나은 이유
13557정성태2/18/20241921Windows: 258. Task Scheduler의 Author 속성 값을 변경하는 방법
13556정성태2/17/20241973Windows: 257. Windows - Symbolic (hard/soft) Link 및 Junction 차이점
13555정성태2/15/20242116닷넷: 2216. C# - SemaphoreSlim 사용 시 주의점
13554정성태2/15/20241861VS.NET IDE: 189. Visual Studio - 닷넷 소스코드 디컴파일 찾기가 안 될 때
13553정성태2/14/20241944닷넷: 2215. windbg - thin/fat lock 없이 동작하는 Monitor.Wait + Pulse
13552정성태2/13/20241896닷넷: 2214. windbg - Monitor.Enter의 thin lock과 fat lock
13551정성태2/12/20242092닷넷: 2213. ASP.NET/Core 웹 응용 프로그램 - 2차 스레드의 예외로 인한 비정상 종료
13550정성태2/11/20242208Windows: 256. C# - Server socket이 닫히면 Accept 시켰던 자식 소켓이 닫힐까요?
13549정성태2/3/20242507개발 환경 구성: 706. C# - 컨테이너에서 실행하기 위한 (소켓) 콘솔 프로젝트 구성
13548정성태2/1/20242336개발 환경 구성: 705. "Docker Desktop for Windows" - ASP.NET Core 응용 프로그램의 소켓 주소 바인딩(IPv4/IPv6 loopback, Any)
13547정성태1/31/20242086개발 환경 구성: 704. Visual Studio - .NET 8 프로젝트부터 dockerfile에 추가된 "USER app" 설정
13546정성태1/30/20241952Windows: 255. (디버거의 영향 등으로) 대상 프로세스가 멈추면 Socket KeepAlive로 연결이 끊길까요?
13545정성태1/30/20241862닷넷: 2212. ASP.NET Core - 우선순위에 따른 HTTP/HTTPS 호스트:포트 바인딩 방법
13544정성태1/30/20241885오류 유형: 894. Microsoft.Data.SqlClient - Could not load file or assembly 'System.Security.Permissions, ...'
13543정성태1/30/20241882Windows: 254. Windows - 기본 사용 중인 5357 포트 비활성화는 방법
13542정성태1/30/20241913오류 유형: 893. Visual Studio - Web Application을 실행하지 못하는 IISExpress - 두 번째 이야기
13541정성태1/29/20241975VS.NET IDE: 188. launchSettings.json의 useSSL 옵션
13540정성태1/29/20242081Linux: 69. 리눅스 - "Docker Desktop for Windows" Container 환경에서 IPv6 Loopback Address 바인딩 오류
13539정성태1/26/20242365개발 환경 구성: 703. Visual Studio - launchSettings.json을 이용한 HTTP/HTTPS 포트 바인딩
13538정성태1/25/20242419닷넷: 2211. C# - NonGC(FOH) 영역에 .NET 개체를 생성파일 다운로드1
13537정성태1/24/20242517닷넷: 2210. C# - Native 메모리에 .NET 개체를 생성파일 다운로드1
1  2  [3]  4  5  6  7  8  9  10  11  12  13  14  15  ...