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

비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  67  68  69  70  71  72  73  [74]  75  ...
NoWriterDateCnt.TitleFile(s)
11794정성태12/16/201810001오류 유형: 508. Get-AzureWebsite : Request to a downlevel service failed.
11793정성태12/16/201811642개발 환경 구성: 423. NuGet 패키지 제작 - Native와 Managed DLL을 분리하는 방법 [1]
11792정성태12/11/201812404Graphics: 34. .NET으로 구현하는 OpenGL (11) - Per-Pixel Lighting파일 다운로드1
11791정성태12/11/201812411VS.NET IDE: 130. C/C++ 프로젝트의 시작 프로그램으로 .NET Core EXE를 지정하는 경우 닷넷 디버깅이 안 되는 문제 [1]
11790정성태12/11/201810721오류 유형: 507. Could not save daemon configuration to C:\ProgramData\Docker\config\daemon.json: Access to the path 'C:\ProgramData\Docker\config' is denied.
11789정성태12/10/201820634Windows: 153. C# - USB 장치의 연결 및 해제 알림을 위한 WM_DEVICECHANGE 메시지 처리 [2]파일 다운로드2
11788정성태12/4/201810551오류 유형: 506. SqlClient - Value was either too large or too small for an Int32.Couldn't store <2151292191> in ... Column
11787정성태11/29/201814521Graphics: 33. .NET으로 구현하는 OpenGL (9), (10) - OBJ File Format, Loading 3D Models파일 다운로드1
11786정성태11/29/201811162오류 유형: 505. OpenGL.NET 예제 실행 시 "Managed Debugging Assistant 'CallbackOnCollectedDelegate'" 예외 발생
11785정성태11/21/201813588디버깅 기술: 120. windbg 분석 사례 - ODP.NET 사용 시 Finalizer에서 System.AccessViolationException 예외 발생으로 인한 비정상 종료
11784정성태11/18/201813284Graphics: 32. .NET으로 구현하는 OpenGL (7), (8) - Matrices and Uniform Variables, Model, View & Projection Matrices파일 다운로드1
11783정성태11/18/201811381오류 유형: 504. 윈도우 환경에서 docker가 설치된 컴퓨터 간의 ping IP 주소 풀이 오류
11782정성태11/18/201811150Windows: 152. 윈도우 10에서 사라진 "Adapters and Bindings" 네트워크 우선순위 조정 기능 - 두 번째 이야기
11781정성태11/17/201813363개발 환경 구성: 422. SFML.NET 라이브러리 설정 방법 [1]파일 다운로드1
11780정성태11/17/201814836오류 유형: 503. vcpkg install bzip2 빌드 에러 - "Error: Building package bzip2:x86-windows failed with: BUILD_FAILED"
11779정성태11/17/201815223개발 환경 구성: 421. vcpkg 업데이트 [1]
11778정성태11/14/201813009.NET Framework: 803. UWP 앱에서 한 컴퓨터(localhost, 127.0.0.1) 내에서의 소켓 연결
11777정성태11/13/201812025오류 유형: 502. Your project does not reference "..." framework. Add a reference to "..." in the "TargetFrameworks" property of your project file and then re-run NuGet restore.
11776정성태11/13/201811276.NET Framework: 802. Windows에 로그인한 계정이 마이크로소프트의 계정인지, 로컬 계정인지 알아내는 방법
11775정성태11/13/201813827Graphics: 31. .NET으로 구현하는 OpenGL (6) - Texturing파일 다운로드1
11774정성태11/8/201811680Graphics: 30. .NET으로 구현하는 OpenGL (4), (5) - Shader파일 다운로드1
11773정성태11/7/201811448Graphics: 29. .NET으로 구현하는 OpenGL (3) - Index Buffer파일 다운로드1
11772정성태11/6/201813723Graphics: 28. .NET으로 구현하는 OpenGL (2) - VAO, VBO파일 다운로드1
11771정성태11/5/201812900사물인터넷: 56. Audio Jack 커넥터의 IR 적외선 송신기 - 두 번째 이야기 [1]
11770정성태11/5/201819925Graphics: 27. .NET으로 구현하는 OpenGL (1) - OpenGL.Net 라이브러리 [3]파일 다운로드1
11769정성태11/5/201811742오류 유형: 501. 프로젝트 msbuild Publish 후 connectionStrings의 문자열이 $(ReplacableToken_...)로 바뀌는 문제
... 61  62  63  64  65  66  67  68  69  70  71  72  73  [74]  75  ...