블로그 이미지
윤영식
Full Stacker, Application Architecter, KnowHow Dispenser and Bike Rider

Publication

Category

Recent Post

'Computer Engineering/Want to Know Terms'에 해당되는 글 2

  1. 2015.01.02 [Terms] Test Double - Mock, Fake
  2. 2015.01.01 [Terms] Syntactic sugar

구글은 테스트를 어떻게 하는가라는 책에서 SET(Software Engineer in Test)가 프로토콜 버퍼를 기반으로 개발하는 서비스가 외부의 서비스와 연계를 위한 투명성을 확보하고 프로토콜 버퍼의 데이터 스팩에 기반해 통합 테스트를 위해 Mock, Fake를 작성한다는 이야기가 나온다. xUnitPattern 사이트를 보면 Test Double에 대한 내용이 나온다. 이것은 테스트하려는 시스템(SUT) 즉 개발하는 서비스에서 단위 테스트를 하려 할 때 실제 의존하는 컴포넌트 (Depended-on Component, DOC)를 사용할 수 없으면 Test Double로 교체해서 테스트를 할 수 있다. Mock, Fake, Stub등이 하기 그림과 같이 Test Double 박스에 위치한다. 그래서 Mock, Fake, Stub등은 Test Double에 속한다. 







Mock Object 


  - 위키피디아에서 Mock Object에 대한 정의

    + 목 오브젝트는 실제 오브젝트의 행위를 흉내낸(simulated) 오브젝트이다. 

    + 주로 어떤 오브젝트의 행위를 테스트하기위해 만든다

    + 실제 오브젝트의 인터페이스를 사용한다. 

    + 예외(exception)나 행(hang)을 일으켜 외부시스템과 연계시 일어날 수 있는 오류를 테스트 할 수 있다. 

    + TDD(Test-Driven Developmen)에서 목 오브젝트를 사용해 단위 테스트(Unit Test)를 수행해 개발자가 SUT(System Under Test)

       하에서 다른 의존관계 라이브러리없이 기대되는 행위 테스트에 집중토록 한다. 

    + 외부연계로 데이터베이스, 웹서비스, 다른 서비스 연계등에 대해 SoC(Separation of Concerns)을 통해 해결토록 도와준다. 

       앵귤러는 module 개념으로 복잡한 웹 개발환경을 확장가능하게 만들어 주고있다. 

       이런 외부 연계에 관여하는 오브젝트를 목 오브젝트로 만들어 테스트에 집중토록 한다. 

In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways. A programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the dynamic behavior of a human in vehicle impacts.


 - xUnit Pattern 의 Mock Object 

   + 목 오브젝트는 행위를 검증하는데 좋다 (Behavior Verification)

   + 그림에서 DOC (Depended-on Component)를 대신해서 Mock Object를 사용


    


  - 스택오버플로우

    + Stub : 미리 정의된 답을 제공하는 메소드를 가진 오브젝트 

    + Mock : 받기를 기대하는 호출스팩을 미리 프로그램한 오브젝트  

    + Fake : 제한된 능력을 가진 오브젝트 

    + Martin Fowler 이야기 : Mocks Aren't Stubs

Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production


Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it 'sent', or maybe only how many messages it 'sent'.


Mocks are what we are talking about here: objects pre-programmed with expectations which form a specification of the calls they are expected to receive.





Fake Object 


  - 스택오버플로우 

    + 고정된 데이터와 로직도 없는 인터페이스를 구현한 클래스 

Fake: a class that implements an interface but contains fixed data and no logic. Simply returns "good" or "bad" data depending on the implementation.


Mock: a class that implements an interface and allows the ability to dynamically set the values to return/exceptions to throw from particular methods and provides the ability to check if particular methods have been called/not called.


Stub: Like a mock class, except that it doesn't provide the ability to verify that methods have been called/not called.


  - xUnitPattern의 Fake Object


    


   * stub, spy에 대해서는 xUnitPattern 사이트 참조하자. 실제 예제를 앵귤러로 넣어 보면 좋겠다. 




<참조> 


  - Test Double 위키피이다

  - Test Double Pattern




'Computer Engineering > Want to Know Terms' 카테고리의 다른 글

[Terms] Syntactic sugar  (0) 2015.01.01
posted by 윤영식

전산이나 컴퓨터 용어를 그때 그때 찾아 보지만 정리를 하지 않고 있다. 그냥 잡학 사전처럼 나만의 용어 정리를 해보고 싶다.



Syntactic sugar

  

  - 위키피디아

    + 사람이 이해하고 쉽고 표현하기 쉽게 컴퓨터 언어를 디자인해 놓은 문맥이다. 

    + 사람이 사용하기 달콤하다는 것에 유래되었고 이들은 깔끔하고 명확하게 표현가능하다는 특징을 지닌다. 

    예로 Array를 든다.

get_array(Array, vector(i, j)) 로 표현하는 대신 Array[i,j] 와 같이 표현한다. 또는 

set_array(Array, vector(i,j), value) 를 Array[i,j] = value로 표현한다. 


  - 프로그래밍으로의 신택티 슈거

    + JSON can be considered SyntacticSugar for XML.

All languages are eventually translated to machine code, and therefore all language constructs could be termed (extremely useful) "sugar" around the operations of the machine.


  - 구글러 오스마니가 표현한 글을 보고 궁금해서 찾아봄 

Preview of ES6 Classes in Chrome. Syntactical sugar over today’s objects and prototypes. Cleaner syntax:


Traceur and 6to5 support minimal ES6 classes, https://6to5.github.io/features.html#classes-1 & https://github.com/esnext/es6-class compiles them down to ES5 too


궁금한건 빨리 정리하고 가자. 

'Computer Engineering > Want to Know Terms' 카테고리의 다른 글

[Terms] Test Double - Mock, Fake  (0) 2015.01.02
posted by 윤영식
prev 1 next