Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 260. C# Code Coverage 도구 - Semantic Designs 소개 [링크 복사], [링크+제목 복사],
조회: 15213
글쓴 사람
정성태 (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)
13069정성태5/26/20229678.NET Framework: 2019. C# - .NET에서 제공하는 3가지 Timer 비교 [2]
13068정성태5/24/20228107.NET Framework: 2018. C# - 일정 크기를 할당하는 동안 GC를 (가능한) 멈추는 방법 [1]파일 다운로드1
13067정성태5/23/20227417Windows: 206. Outlook - 1년 이상 지난 메일이 기본적으로 안 보이는 문제
13066정성태5/23/20226779Windows: 205. Windows 11 - Windows + S(또는 Q)로 뜨는 작업 표시줄의 검색 바가 동작하지 않는 경우
13065정성태5/20/20227407.NET Framework: 2017. C# - Windows I/O Ring 소개 [2]파일 다운로드1
13064정성태5/18/20226994.NET Framework: 2016. C# - JIT 컴파일러의 인라인 메서드 처리 유무
13063정성태5/18/20227443.NET Framework: 2015. C# - 인라인 메서드(inline methods)
13062정성태5/17/20228161.NET Framework: 2014. C# - async/await 그리고 스레드 (4) 비동기 I/O 재현파일 다운로드1
13061정성태5/16/20226990.NET Framework: 2013. C# - FILE_FLAG_OVERLAPPED가 적용된 파일의 읽기/쓰기 시 Position 관리파일 다운로드1
13060정성태5/15/20229551.NET Framework: 2012. C# - async/await 그리고 스레드 (3) Task.Delay 재현파일 다운로드1
13059정성태5/14/20227938.NET Framework: 2011. C# - CLR ThreadPool의 I/O 스레드에 작업을 맡기는 방법 [1]파일 다운로드1
13058정성태5/13/20227829.NET Framework: 2010. C# - ThreadPool.SetMaxThreads 사용법
13057정성태5/12/20229502오류 유형: 812. 파이썬 - ImportError: cannot import name ...
13056정성태5/12/20226618.NET Framework: 2009. C# - async/await 그리고 스레드 (2) MyTask의 호출 흐름 [2]파일 다운로드1
13055정성태5/11/20229611.NET Framework: 2008. C# - async/await 그리고 스레드 (1) MyTask로 재현 [11]파일 다운로드1
13054정성태5/11/20227051.NET Framework: 2007. C# - 10진수 숫자를 담은 문자열을 숫자로 변환하는 방법 [11]파일 다운로드1
13053정성태5/10/20226716.NET Framework: 2006. C# - GC.KeepAlive 메서드의 역할
13052정성태5/9/20226766.NET Framework: 2005. C# - 생성한 참조 개체가 언제 GC의 정리 대상이 될까요?
13051정성태5/8/20226637.NET Framework: 2004. C# XingAPI - ACF 검색 결과로 구한 CSV 파일을 통해 퀀트 종목 찾기파일 다운로드1
13050정성태5/6/20226712.NET Framework: 2003. C# - COM 개체의 이벤트 핸들러에서 발생하는 예외에 대한 CLR의 특별 대우파일 다운로드1
13049정성태5/6/20225653오류 유형: 811. GoLand - Error: Cannot find package
13048정성태5/6/20226852오류 유형: 810. "ASUS TUF GAMING B550M-PLUS (WI-FI)" 모델에서 블루투스 장치가 인식이 안 되는 문제
13047정성태5/6/20226857오류 유형: 809. Speech Recognition could not start
13046정성태5/5/20227136.NET Framework: 2002. C# XingAPI - ACF 파일을 이용한 퀀트 종목 찾기(t1857)
13045정성태5/5/20227149.NET Framework: 2001. C# XingAPI - 주식 종목에 따른 PBR, PER, ROE 구하는 방법(t3341 예제)
13044정성태5/4/20226579오류 유형: 808. error : clang++ exited with code 127
... 16  17  18  19  20  21  22  [23]  24  25  26  27  28  29  30  ...