Test-Driven Development (TDD) is the practice of working in a structured cycle where writing tests comes before writing production code. The process involves three steps, sometimes called the red-green-refactor cycle:
- Write a failing test
- Make the test pass by writing just enough production code
- Refactor the production code to meet your quality standards
Research shows TDD has several benefits: it improves test coverage, reduces the number of bugs, increases confidence, and facilitates code reuse. This practice also helps reduce distractions and keep you in the flow. TDD also has its limitations and is not a silver bullet! See the Wikipedia article about TDD for a detailed explanation and references.
Here is a short practical example. Assume you need to modify the following voting algorithm to support the option for voters to abstain:
1. We start by writing a failing test - as expected, the test doesn't even compile:
2. We fix the compilation error by including the missing enum option:
Now that the test compiles, we fix the production code to get all tests passing:
3. We now refactor the code to improve clarity, and complete an iteration of the TDD cycle:
New research shows how Google AI helps radiologists detect breast cancer earlier and more accurately, while giving radiologists more time for patient care.



Gemini for Education is now in all 20 Malaysian public universities, reaching 600,000 students and 75,000 faculty members.
Google is honoring International Women’s Day and Women’s History Month across its products along with a new film on Dr. Marian Croak.