Legacy code (โค้ดที่มักไม่มีเทสต์และเปลี่ยนแปลงยาก) เป็นเรื่องท้าทายในการทดสอบ — มันอาจมี dependency ที่พันกันยุ่งเหยิงและไม่มีเทสต์ การเพิ่มเทสต์อย่างปลอดภัยเกี่ยวข้องกับเทคนิคอย่าง characterization test, seam สำหรับการตัด dependency และการปรับปรุงทีละขั้น ซึ่งช่วยให้เปลี่ยนแปลงได้ปลอดภัยขึ้น
ความท้าทายของ legacy code
Legacy code is often: untested, tightly coupled, hard to understand, risky to change:
→ no tests → changing it is dangerous (you can't tell if you broke something)
→ hard to test → dependencies are tangled (can't isolate units); not designed for testing
→ a chicken-and-egg problem: to change safely you need tests, but it's hard to test.
