"매 컴파일 전에 매 동작을 바꾸는 매 접점". Preprocessing seam은 Michael Feathers "Working Effectively with Legacy Code" (2004) 의 매 3대 seam (preprocessing / link / object) 중 매 첫 번째 — 매 source 수정 없이 매 매크로/include 치환으로 매 test isolation 가능 지점. C/C++ 같은 매 preprocessor-heavy language의 매 testability 회복 도구.
매 핵심
매 Seam 정의
매 Seam: 매 source 수정 없이 매 동작 변경 가능한 매 지점.
매 Enabling point: 매 seam을 매 활용하는 매 mechanism (here: preprocessor).
매 3종류: preprocessing / link / object.
매 Preprocessing seam 작동
#include "db.h" → 매 test 시 매 fake db.h include path 우선.
#define malloc test_malloc → 매 allocator hook.
#ifdef TESTING 매 conditional compile.
매 응용
Legacy C codebase 매 unit test 추가.
Embedded firmware의 매 hardware register hook.
Time/random 매 deterministic replacement.
💻 패턴
Header substitution seam
// production: src/db.h
intdb_query(constchar*sql);// test/fakes/db.h — 매 same signature, 매 fake impl
intdb_query(constchar*sql){return42;}// CMake test target
target_include_directories(my_testPRIVATEtest/fakessrc)// 매 fakes 우선
// production link: real_sensor.o
intread_sensor(void);// test link: fake_sensor.o 매 same symbol, 매 different impl
intread_sensor(void){returninjected_value;}// gcc test.c fake_sensor.o -o test // 매 real_sensor.o 미포함
Python equivalent — sys.modules patch
# 매 import-time seamimportsys,typesfake=types.ModuleType("db")fake.query=lambdasql:42sys.modules["db"]=fakeimportservice# 매 service.py 의 `import db` → fake
매 결정 기준
상황
Approach
C/C++ legacy, 매 source 매 못 건드림
Preprocessing seam
Static lib, 매 link-time control
Link seam
Java/.NET runtime
Object seam (subclass / DI)
Python
sys.modules / monkeypatch
기본값: Object seam 우선, 매 안 되면 link → preprocessing 순.