TDD: Get me started
by Chance Smith
In case you haven’t heard, we first need to talk about what Test Driven Development (TDD) is.
TDD?
It’s a seemingly simple workflow. You just write a failing test first and then write code that passes your test. One at a time.
Yeah, sounds nuts, right?! Let me explain the steps…
- RED: Write a failing test
- GREEN: Write just enough production code to pass that test
- REFACTOR: Refactor any of your code without failing a test. Stay green.
These steps are all thanks to Kent Beck and Uncle Bob. Go read their books. Uncle Bob wrote code for 20 years before he went on all in on TDD. 🤯
TDD is a simple but challenging process. You will struggle, but with much software engineering maturity, you will get better at this. Start now. Worry about doing it wrong later.
Why you need TDD
Let’s list the ways:
- less browser refreshing, because your tests are testing that part of the code for you
- run your code less, because your tests are testing that part of the code for you
- let the failing tests show you what to fix or add next
- refactor or abstract anything you want, just keep the green lights on
How do I start writing tests?
Go Google “How to write test in python” or “Javascript TDD.” Watch and read all you can.
Here is a collection of testing videos that our team found helpful to get us started.
Also use Katas, the act of practicing to memorize and perfect a form or movements. Katas work in development and help us get into a new programming language and especially learning to test our code. Here is a small javascript todo-list kata our team created and we talk about it often. This shows a simple example of how we add tests to logic and UI.
Go write some tests
Next time you code, ask yourself, “How can I write a test first?”
I’m going to say it again…
Start now. Worry about doing it wrong later.
Need help getting started?
Our team would be happy to help you get started with testing Python, C#, or Javascript.