Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 260. C# Code Coverage 도구 - Semantic Designs 소개 [링크 복사], [링크+제목 복사],
조회: 15212
글쓴 사람
정성태 (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)
12919정성태1/13/20226504Windows: 199. Host Network Service (HNS)에 의해서 점유되는 포트
12918정성태1/13/20226723Linux: 47. WSL - shell script에서 설정한 환경 변수가 스크립트 실행 후 반영되지 않는 문제
12917정성태1/12/20225914오류 유형: 785. C# - The type or namespace name '...' could not be found (are you missing a using directive or an assembly reference?)
12916정성태1/12/20225681오류 유형: 784. TFS - One or more source control bindings for this solution are not valid and are listed below.
12915정성태1/11/20225983오류 유형: 783. Visual Studio - We didn't find any interpreters
12914정성태1/11/20227995VS.NET IDE: 172. 비주얼 스튜디오 2022의 파이선 개발 환경 지원
12913정성태1/11/20228506.NET Framework: 1133. C# - byte * (바이트 포인터)를 FileStream으로 쓰는 방법 [1]
12912정성태1/11/20229159개발 환경 구성: 623. ffmpeg.exe를 사용해 비디오 파일의 이미지를 PGM(Portable Gray Map) 파일 포맷으로 출력하는 방법 [1]
12911정성태1/11/20226388VS.NET IDE: 171. 비주얼 스튜디오 - 더 이상 만들 수 없는 "ASP.NET Core 3.1 Web Application (.NET Framework)" 프로젝트
12910정성태1/10/20226881제니퍼 .NET: 30. 제니퍼 닷넷 적용 사례 (8) - CPU high와 DB 쿼리 성능에 문제가 함께 있는 사이트
12909정성태1/10/20228258오류 유형: 782. Visual Studio 2022 설치 시 "Couldn't install Microsoft.VisualCpp.Redist.14.Latest"
12908정성태1/10/20226085.NET Framework: 1132. C# - ref/out 매개변수의 IL 코드 처리
12907정성태1/9/20226612오류 유형: 781. (youtube-dl.exe) 실행 시 "This app can't run on your PC" / "Access is denied." 오류 발생
12906정성태1/9/20227272.NET Framework: 1131. C# - 네임스페이스까지 동일한 타입을 2개의 DLL에서 제공하는 경우 충돌을 우회하는 방법 [1]파일 다운로드1
12905정성태1/8/20226924오류 유형: 780. Could not load file or assembly 'Microsoft.VisualStudio.TextTemplating.VSHost.15.0, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
12904정성태1/8/20228899개발 환경 구성: 623. Visual Studio 2022 빌드 환경을 위한 github Actions 설정 [1]
12903정성태1/7/20227513.NET Framework: 1130. C# - ELEMENT_TYPE_INTERNAL 유형의 사용 예
12902정성태1/7/20227554오류 유형: 779. SQL 서버 로그인 에러 - provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.
12901정성태1/5/20227577오류 유형: 778. C# - .NET 5+에서 warning CA1416: This call site is reachable on all platforms. '...' is only supported on: 'windows' 경고 발생
12900정성태1/5/20229263개발 환경 구성: 622. vcpkg로 ffmpeg를 빌드하는 경우 생성될 구성 요소 제어하는 방법
12899정성태1/3/20228755개발 환경 구성: 621. windbg에서 python 스크립트 실행하는 방법 - pykd (2)
12898정성태1/2/20229337.NET Framework: 1129. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 비디오 인코딩 예제(encode_video.c) [1]파일 다운로드1
12897정성태1/2/20228166.NET Framework: 1128. C# - 화면 캡처한 이미지를 ffmpeg(FFmpeg.AutoGen)로 동영상 처리 [4]파일 다운로드1
12896정성태1/1/202211123.NET Framework: 1127. C# - FFmpeg.AutoGen 라이브러리를 이용한 기본 프로젝트 구성파일 다운로드1
12895정성태12/31/20219544.NET Framework: 1126. C# - snagit처럼 화면 캡처를 연속으로 수행해 동영상 제작 [1]파일 다운로드1
12894정성태12/30/20217509.NET Framework: 1125. C# - DefaultObjectPool<T>의 IDisposable 개체에 대한 풀링 문제 [3]파일 다운로드1
... 16  17  18  19  20  21  22  23  24  25  26  27  28  [29]  30  ...