SqueakByExample:7.8: Difference between revisions

From 흡혈양파의 번역工房
Jump to navigation Jump to search
(SBE SUnit의구현 페이지 추가)
 
mNo edit summary
Line 11: Line 11:




메소드 TestCase»run은 테스트들의 결과들을 축적할 TestResult의 인스턴스를 만들고, 그 다음 자신에게 message run:을 보냅니다. (그림 7.3을 보십시오)   
메서드 TestCase»run은 테스트들의 결과들을 축적할 TestResult의 인스턴스를 만들고, 그 다음 자신에게 message run:을 보냅니다. (그림 7.3을 보십시오)   




메소드 7.10: test case 실행하기  
메서드 7.10: test case 실행하기  
<syntaxhighlight lang="smalltalk">
<syntaxhighlight lang="smalltalk">
TestCase»run
TestCase»run
Line 24: Line 24:




메소드 TestCase»run: 는 메시지 runCase:를 테스트 결과에 발송합니다.
메서드 TestCase»run: 는 메시지 runCase:를 테스트 결과에 발송합니다.




메소드 7.11: test case를 테스트 결과에 패스하기
메서드 7.11: test case를 테스트 결과에 패스하기
<syntaxhighlight lang="smalltalk">
<syntaxhighlight lang="smalltalk">
TestCase»run: aResult
TestCase»run: aResult
Line 34: Line 34:




메소드 TestResult»runCase:는 테스트를 실행하기 위해 개별적 테스트에 메시지 runCase를 발송합니다. TestResult»runCase는 테스트가 실행되는 동안 제기될 모든 예외들을 다루며, 메시지 runCase를 그것에 보내어 TestCase를 실행하고, 에러, 실패 그리고 패스의 숫자를 카운트합니다.
메서드 TestResult»runCase:는 테스트를 실행하기 위해 개별적 테스트에 메시지 runCase를 발송합니다. TestResult»runCase는 테스트가 실행되는 동안 제기될 모든 예외들을 다루며, 메시지 runCase를 그것에 보내어 TestCase를 실행하고, 에러, 실패 그리고 패스의 숫자를 카운트합니다.




메소드 7.12: test case 에러와 실패(failures)를 잡아내기
메서드 7.12: test case 에러와 실패(failures)를 잡아내기
<syntaxhighlight lang="smalltalk">
<syntaxhighlight lang="smalltalk">
TestResult»runCase: aTestCase
TestResult»runCase: aTestCase
Line 59: Line 59:




메소드 TestCase»runCase는 메시지 setUp 와 tearDown을 아래에 보이는 것 처럼 발송합니다.  
메서드 TestCase»runCase는 메시지 setUp 와 tearDown을 아래에 보이는 것 처럼 발송합니다.  




메소드 7.13: Test case 템플릿 메소드 (Test Case Template Method)
메서드 7.13: Test case 템플릿 메서드 (Test Case Template Method)
<syntaxhighlight lang="smalltalk">
<syntaxhighlight lang="smalltalk">
TestCase»runCase
TestCase»runCase
Line 72: Line 72:
===TestSuite 실행하기===
===TestSuite 실행하기===


한 개 이상의 테스트를 실행하기 위해, 우리는 관련된 테스트들을 포함하고 있는 TestSuite에 메시지를 발송합니다. TestCase 클래스는 그것의 메소드들로부터, 테스트 스위트(test suite)를 구축하기 위해 몇 가지 기능을 제공합니다. 표현식 MyTestCase buildSuiteFromSelectors는 MyTestCase 클래스에서 정의된 모든 테스트들을 포함하고 있는 스위트(suite)를 리턴합니다. 이 프로세스의 코어는,
한 개 이상의 테스트를 실행하기 위해, 우리는 관련된 테스트들을 포함하고 있는 TestSuite에 메시지를 발송합니다. TestCase 클래스는 그것의 메서드들로부터, 테스트 스위트(test suite)를 구축하기 위해 몇 가지 기능을 제공합니다. 표현식 MyTestCase buildSuiteFromSelectors는 MyTestCase 클래스에서 정의된 모든 테스트들을 포함하고 있는 스위트(suite)를 리턴합니다. 이 프로세스의 코어는,




메소드 7.14: 자동 구축 테스트 스위트(Auto-building the test suite)
메서드 7.14: 자동 구축 테스트 스위트(Auto-building the test suite)
<syntaxhighlight lang="smalltalk">
<syntaxhighlight lang="smalltalk">
TestCase class»testSelectors
TestCase class»testSelectors
Line 83: Line 83:




메소드 TestSuite»run는 TestResult의 인스턴스를 만들고 모든 리소스가 사용가능한지를 확인하고 그 다음 그 자신에게 실행중인 메시지를 발송합니다: 그 작업은 스위트에 있는 모든 테스트를 실행시킵니다. 그 이후 모든 리소스가 릴리즈됩니다.
메서드 TestSuite»run는 TestResult의 인스턴스를 만들고 모든 리소스가 사용가능한지를 확인하고 그 다음 그 자신에게 실행중인 메시지를 발송합니다: 그 작업은 스위트에 있는 모든 테스트를 실행시킵니다. 그 이후 모든 리소스가 릴리즈됩니다.




메소드 7.15 테스트 스위트(test suite)실행하기
메서드 7.15 테스트 스위트(test suite)실행하기
<syntaxhighlight lang="smalltalk">
<syntaxhighlight lang="smalltalk">
TestSuite»run
TestSuite»run
Line 100: Line 100:




메소드 7.16: 테스트 결과에 테스트 스위트(test suite) 패스하기
메서드 7.16: 테스트 결과에 테스트 스위트(test suite) 패스하기
<syntaxhighlight lang="smalltalk">
<syntaxhighlight lang="smalltalk">
TestSuite»run: aResult
TestSuite»run: aResult
Line 110: Line 110:




클래스 TestResource와 그것의 서브클래스들은 현재의 클래스 메소드를 사용하여 접근할 수 있고 만들 수 있는 현재 만든 그 서브클래스들의 인스턴스들을(클래스당 하나의)지속적으로 파악합니다. 이 인스턴스는 테스트가 실행을 마치거나 리소스가 리셋될 대 클리어 됩니다.
클래스 TestResource와 그것의 서브클래스들은 현재의 클래스 메서드를 사용하여 접근할 수 있고 만들 수 있는 현재 만든 그 서브클래스들의 인스턴스들을(클래스당 하나의)지속적으로 파악합니다. 이 인스턴스는 테스트가 실행을 마치거나 리소스가 리셋될 대 클리어 됩니다.


리소스 유효성 점검(the resource availability check)은 클래스 메소드 '''TestResource class»isAvailable'''에 보이는 것 처럼 필요할 경우 다시 만들어지는 작업을 가능하게 합니다. TestResouce 인스턴스 생성을 하는 동안, 그것은 초기화되고 메소드 setUp이 호출됩니다.  
리소스 유효성 점검(the resource availability check)은 클래스 메서드 '''TestResource class»isAvailable'''에 보이는 것 처럼 필요할 경우 다시 만들어지는 작업을 가능하게 합니다. TestResouce 인스턴스 생성을 하는 동안, 그것은 초기화되고 메서드 setUp이 호출됩니다.  




메소드 7.17: 테스트 리소스 유효성(Test resource availability)
메서드 7.17: 테스트 리소스 유효성(Test resource availability)
<syntaxhighlight lang="smalltalk">
<syntaxhighlight lang="smalltalk">
TestResource class»isAvailable
TestResource class»isAvailable
Line 122: Line 122:




메소드 7.18:테스트 리소스 생성
메서드 7.18:테스트 리소스 생성
<syntaxhighlight lang="smalltalk">
<syntaxhighlight lang="smalltalk">
TestResource class»current
TestResource class»current
Line 130: Line 130:




메소드 7.19: 테스트 리소스
메서드 7.19: 테스트 리소스
<syntaxhighlight lang="smalltalk">
<syntaxhighlight lang="smalltalk">
TestResource»initialize
TestResource»initialize

Revision as of 04:45, 30 August 2012

SUnit의 구현

SUnit의 실행은 스몰토크 프레임 워크의 흥미로운 케이스 스터디를 만듭니다. 다음 테스트의 실행에(execution) 의한 구현(implementation)의 몇 가지 핵심 측면들을 살펴봅시다.

테스트 실행하기

어떤 테스트를 실행하기 위해, 우리는 표현식 (aTestClass selector: aSymbol)run을 평가합니다.


그림 7.3: 테스트 실행하기


메서드 TestCase»run은 테스트들의 결과들을 축적할 TestResult의 인스턴스를 만들고, 그 다음 자신에게 message run:을 보냅니다. (그림 7.3을 보십시오)


메서드 7.10: test case 실행하기

TestCase»run
  | result |
  result := TestResult new.
  self run: result.
  result


메서드 TestCase»run: 는 메시지 runCase:를 테스트 결과에 발송합니다.


메서드 7.11: test case를 테스트 결과에 패스하기

TestCase»run: aResult
  aResult runCase: self


메서드 TestResult»runCase:는 테스트를 실행하기 위해 개별적 테스트에 메시지 runCase를 발송합니다. TestResult»runCase는 테스트가 실행되는 동안 제기될 모든 예외들을 다루며, 메시지 runCase를 그것에 보내어 TestCase를 실행하고, 에러, 실패 그리고 패스의 숫자를 카운트합니다.


메서드 7.12: test case 에러와 실패(failures)를 잡아내기

TestResult»runCase: aTestCase
  | testCasePassed |
  testCasePassed := true.
  [[aTestCase runCase]
    on: self class failure
    do:
      [:signal |
      failures add: aTestCase.
      testCasePassed := false.
      signal return: false]]
          on: self class error
          do:
          [:signal |
          errors add: aTestCase.
          testCasePassed := false.
          signal return: false].
  testCasePassed ifTrue: [passed add: aTestCase]


메서드 TestCase»runCase는 메시지 setUp 와 tearDown을 아래에 보이는 것 처럼 발송합니다.


메서드 7.13: Test case 템플릿 메서드 (Test Case Template Method)

TestCase»runCase
  self setUp.
  [self performTest] ensure: [self tearDown]


TestSuite 실행하기

한 개 이상의 테스트를 실행하기 위해, 우리는 관련된 테스트들을 포함하고 있는 TestSuite에 메시지를 발송합니다. TestCase 클래스는 그것의 메서드들로부터, 테스트 스위트(test suite)를 구축하기 위해 몇 가지 기능을 제공합니다. 표현식 MyTestCase buildSuiteFromSelectors는 MyTestCase 클래스에서 정의된 모든 테스트들을 포함하고 있는 스위트(suite)를 리턴합니다. 이 프로세스의 코어는,


메서드 7.14: 자동 구축 테스트 스위트(Auto-building the test suite)

TestCase class»testSelectors
  self selectors asSortedCollection asOrderedCollection select: [:each |
    ('test*' match: each) and: [each numArgs isZero]]


메서드 TestSuite»run는 TestResult의 인스턴스를 만들고 모든 리소스가 사용가능한지를 확인하고 그 다음 그 자신에게 실행중인 메시지를 발송합니다: 그 작업은 스위트에 있는 모든 테스트를 실행시킵니다. 그 이후 모든 리소스가 릴리즈됩니다.


메서드 7.15 테스트 스위트(test suite)실행하기

TestSuite»run
  | result |
  result := TestResult new.
   self areAllResourcesAvailable
    ifFalse: [TestResult signalErrorWith:
      'Resource could not be initialized'].
  [self run: result] ensure: [self resources do:
                     [:each | each reset]].
  result


메서드 7.16: 테스트 결과에 테스트 스위트(test suite) 패스하기

TestSuite»run: aResult
  self tests do:
    [:each |
    self sunitChanged: each.
    each run: aResult]


클래스 TestResource와 그것의 서브클래스들은 현재의 클래스 메서드를 사용하여 접근할 수 있고 만들 수 있는 현재 만든 그 서브클래스들의 인스턴스들을(클래스당 하나의)지속적으로 파악합니다. 이 인스턴스는 테스트가 실행을 마치거나 리소스가 리셋될 대 클리어 됩니다.

리소스 유효성 점검(the resource availability check)은 클래스 메서드 TestResource class»isAvailable에 보이는 것 처럼 필요할 경우 다시 만들어지는 작업을 가능하게 합니다. TestResouce 인스턴스 생성을 하는 동안, 그것은 초기화되고 메서드 setUp이 호출됩니다.


메서드 7.17: 테스트 리소스 유효성(Test resource availability)

TestResource class»isAvailable
  self current notNil


메서드 7.18:테스트 리소스 생성

TestResource class»current
  current isNil ifTrue: [current := self new].
  current


메서드 7.19: 테스트 리소스

TestResource»initialize
  self setUp


Notes