Development & Engineering · Frontier
Test-Driven Development
Test-Driven Development
Write the check for what counts as correct first, then write the code that makes it pass. The order feels backwards, and the point is that the requirements get pinned down at the very start.
TL;DRIn 30 seconds
- Write the check for what counts as correct first, then build the code that satisfies it.
- The order is reversed on purpose — it forces you to think through the requirement and the edge cases before you start.
- Move the checks to the front without thinking and nothing is left but the ritual.
OverviewIn detail
TDD stands for Test-Driven Development. The practice is: first write a check that says how this piece of code ought to behave, then write the implementation that makes it pass. In short, set the standard first and build to it afterwards.
The reversed order earns its keep. If you build the feature first and add checks afterwards, you tend to check only the parts you feel confident about — marking your own exam paper — and the problems slip straight past. Writing the check first pins the requirement down in advance, so the implementation has to satisfy it and any drift shows up immediately. Writing the check also forces you to think about the edges: what happens when the number is zero, what if the input is empty. The cases most often missed float to the surface early.
It isn't the same as 'writing the tests first'. Real TDD is a small loop: write one check, run it and watch it fail, write just enough code to make it pass, then tidy up how it's written. Skip the watching-it-fail step and you have no idea whether the check tests anything at all.
The payoff shows up later. When you change something elsewhere, the checks tell you automatically whether you've broken what used to work, without walking the whole flow by hand each time. The more you change, and the more often, the more that safety net is worth. Sometimes a check stays red, and that isn't bad news — it means the check really is watching something.
Pace matters too: add one check and a little implementation at a time, so when something goes wrong the scope is small and easy to trace back. Change a wide swathe in one go and finding the cause becomes hard. One thing to watch: TDD's real value is forcing you to think through what you want first. Treat it as no more than an order for writing checks, follow it without thinking, and nothing is left but the ritual — you'd do better to spell the requirement out properly and then start.
MythsCommon misunderstandings
- ✕Thinking TDD just means writing tests first ✓The key is running the check and watching it fail, so you know it actually tests something
- ✕Thinking more checks means safer ✓Make them too fine-grained and one change drags a whole row of them along, slowing you down instead
- ✕Thinking the checks exist to police other people ✓Their real use is forcing you to think the requirement through — otherwise it's just a process you went through
In practiceWhere you will meet it
- Before writing the feature, writing one check that says an empty input should raise an error
- After touching old code, running the suite to see whether anything that used to work has broken
- On receiving a requirement, turning its conditions into individual checks first
SummaryThe key points
- Write down the expected behaviour, then write code that satisfies it
- Every loop has to see the check fail first, or you don't know it tests anything
- Its real value is forcing you to think the requirement through in advance
- After a change, the suite tells you automatically whether you broke something
FAQ
What does Test-Driven Development mean?
Write the check for what counts as correct first, then build the code that satisfies it.The order is reversed on purpose — it forces you to think through the requirement and the edge cases before you start.Move the checks to the front without thinking and nothing is left but the ritual.
Where will I run into Test-Driven Development?
Before writing the feature, writing one check that says an empty input should raise an error;After touching old code, running the suite to see whether anything that used to work has broken;On receiving a requirement, turning its conditions into individual checks first。
What do people most often get wrong about Test-Driven Development?
Thinking TDD just means writing tests first — but The key is running the check and watching it fail, so you know it actually tests something;Thinking more checks means safer — but Make them too fine-grained and one change drags a whole row of them along, slowing you down instead。
What are the key points about Test-Driven Development?
Write down the expected behaviour, then write code that satisfies it;Every loop has to see the check fail first, or you don't know it tests anything;Its real value is forcing you to think the requirement through in advance;After a change, the suite tells you automatically whether you broke something。
Common pitfalls Move the checks to the front without thinking and only the ritual is left — better to spell the requirement out first.
Also written asYou may also see it written as
These are all the same concept — the same thing, however it is written in a skill description. Do not mistake different spellings for different ideas.
Entry 75 of 186 · All entries
Keep readingRelated reading
算法(Algorithm)
算法就是做一件事的固定步骤清单。照着一步步做,同样的输入总能得到同样的结果,电脑就是靠它来完成任务的。
Open Source
Open source means the author publishes the recipe as well as the software. Anyone can read it, use it for free, and even change it and pass it on.
GitHub(代码托管平台)
GitHub 是全球程序员存放和分享代码的网站,既能当作品集,也是大家一起改同一份代码的协作台。
前端(Frontend)
前端是软件里你能看见、能点的那一层。按钮、图片、页面动画,都是它做出来的。
Backend
The backend is the half of the software you never see. Every step you take in the interface is handled behind the scenes by it, looking up data and making the decisions.
Automation
Automation means letting a computer repeat a job by rules you set, so work you would otherwise redo by hand every time is handed over entirely.
Where to go nextExplore more
Back to the skills themselves
Most of the concepts covered here come from skills that install into your AI client with a single command.