Exploratory and Spike Solutions
You'll learn when it's okay to set TDD aside temporarily for research, and how to bring those discoveries back into test-driven code.
Sometimes you face a problem where you genuinely don't know the solution yet. Maybe you're investigating a new library, experimenting with an unfamiliar API, or exploring whether an approach is even feasible. Writing tests first doesn't make sense when you don't yet understand what you're building or how it should behave.
This is where spike solutions come in—time-boxed research experiments where you skip TDD to learn quickly. Think of it like sketching rough drafts before committing to the final drawing. You're gathering information, not shipping code.
When to Spike
Use spikes when:
- You're uncertain whether a technical approach will work
- You need to learn an unfamiliar library or framework
- The requirements are too unclear to write meaningful tests
- You're prototyping to understand the problem better
The Critical Transition
Here's the key: spike code is throwaway code. Once you've learned what you needed, you start over with TDD, applying your new knowledge. You write the first failing test, then rebuild the solution properly—this time with confidence about what you're doing.
Alternatively, if the spike is small and clean, you might keep it but immediately wrap it with tests to lock in the behavior you discovered.
The Discipline
Set a time limit for your spike (30 minutes, 2 hours, half a day). When time's up, you either understand the problem well enough to restart with TDD, or you need to timebox another spike. Never let spike code drift into production untested—that defeats the entire safety net TDD provides.
Key Takeaway: Spike solutions let you explore unknown territory without TDD, but they're research tools, not deliverables—always transition discoveries back into properly test-driven code.