Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- TDD
- 유지보수
- 코틀린
- 조영호
- 이펙티브코틀린
- 테스트주도개발
- 개발방법론
- 계층형아키텍처
- 함수형프로그래밍
- 책스터디
- Thymeleaf
- template
- Spring
- 개발서적
- 만들면서배우는클린아키텍처
- 추상화 설계
- web
- 테스트
- 객체지향의사실과오해
- Kotlin
- 스터디
- 헥사고날아키텍처
- Boot Legacy 차이점
- GrokkingFunctionalProgramming
- 클린아키텍처
- 도메인 주도 개발 시작하기
- Java
- FP
- 아키텍처
- DDD
Archives
- Today
- Total
김동형수 개발기
테스트 주도 개발 - 2부 19장 본문
19장 테이블 차리기
빌 웨이크의 3A 패턴
- 준비 (arrange) - 객체를 생성한다.
- 행동 (act) - 어떤 자극을 준다.
- 확인 (assert) - 결과를 검사한다.
테스트 메서드 호출하기
먼저 setUp 호출하기
나중에 tearDown 호출하기
테스트 메서드가 실패하더라도 tearDown 호출하기
여러 개의 테스트 실행하기
수집된 결과를 출력하기
3A 중 두 번째 세 번째는 항상 다르지만 준비 단계는 여러 테스트 걸쳐 동일한 경우가 종종 있다.
이런 패턴이 반복된다면 새로운 객체 생성에 대한 문제에 직면하게 된다.
성능 - 객체 하나만 생성해서 모든 테스트가 이 객체를 쓰게 할 수 있을 것이다.
격리 - 공유된 객체가 다른 테스트에 영향을 끼칠 수 있다.
테스트 커플링을 만들지 말 것.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestCase: | |
def __init__(self, name): | |
self.name = name | |
def run(self): | |
self.setUp() | |
method = getattr(self, self.name) | |
method() | |
def setUp(self): | |
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from TestCase import TestCase | |
from WasRun import WasRun | |
class TestCaseTest(TestCase): | |
def testRunning(self): | |
test = WasRun("testMethod") | |
assert not test.wasRun | |
test.run() | |
assert test.wasRun | |
def testSetUp(self): | |
test = WasRun("testMethod") | |
test.run() | |
assert test.wasSetUp | |
TestCaseTest("testRunning").run() | |
TestCaseTest("testSetUp").run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from TestCase import TestCase | |
from WasRun import WasRun | |
class TestCaseTest(TestCase): | |
def testRunning(self): | |
self.test.run() | |
assert self.test.wasRun | |
def testSetUp(self): | |
self.test.run() | |
assert self.test.wasSetUp | |
def setUp(self): | |
self.test = WasRun("testMethod") | |
TestCaseTest("testRunning").run() | |
TestCaseTest("testSetUp").run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from TestCase import TestCase | |
class WasRun(TestCase): | |
def __init__(self, name): | |
self.wasRun = None | |
TestCase.__init__(self, name) | |
def testMethod(self): | |
self.wasRun = 1 | |
def setUp(self): | |
self.wasSetUp = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from TestCase import TestCase | |
class WasRun(TestCase): | |
def __init__(self, name): | |
self.wasSetUp = None | |
self.wasRun = None | |
TestCase.__init__(self, name) | |
def testMethod(self): | |
self.wasRun = 1 | |
def setUp(self): | |
self.wasRun = None | |
self.wasSetUp = 1 |
테스트 메서드 호출하기먼저 setUp 호출하기
나중에 tearDown 호출하기
테스트 메서드가 실패하더라도 tearDown 호출하기
여러 개의 테스트 실행하기
수집된 결과를 출력하기
정리
- 일단은 테스트를 작성하는 데 있어 간결함이 성능 향상보다 중요하다고 생각하기로 했다.
- setUp()을 테스트하고 구현했다.
- 예제 테스트 케이스를 단순화하기 위해 setUp()을 사용했다.
- 예제 테스트 케이스에 대한 테스트 케이스를 단순화하기 위해 setUp()을 사용했다.
'책 스터디 > [완료] 테스트 주도 개발' 카테고리의 다른 글
테스트 주도 개발 - 2부 21장 (2) | 2022.10.03 |
---|---|
테스트 주도 개발 - 2부 20장 (0) | 2022.09.28 |
테스트 주도 개발 - 2부 18장 (0) | 2022.09.28 |
테스트 주도 개발 - 1부 10장 (0) | 2022.09.23 |
테스트 주도 개발 - 1부 9장 (0) | 2022.09.23 |
Comments