Codementor Events

How I learned Test Driven Developement

Published Feb 24, 2020
How I learned Test Driven Developement

About me

I'm a senior Laravel developer with significant experience in PHP. I've been working with PHP since 1997, and have been focused largely on Laravel since 2014.

Why I wanted to learn Test Driven Developement

I'd heard a lot about test driven development, and automated testing in general, for a long time. I'd always struggled to get any traction when I tried to actually do anything with it.

How I approached learning Test Driven Developement

Getting a sane and reliable testing environment in place had always been a first challenge for me. As I switched to a focus on Laravel, this became much easier as a lot of tools and discussions already existed for a much more specific use case.

Testing, like anything, is a process of continual improvement. I continue to read as much as I can about other's experiences, lessons learned, and approaches. I take on board as much as I can, and reflect on them combined with my own experiences. What's working well? What's not? What tests have saved my pushing bad code? Why? Which have been more work to maintain than value? Why?

Challenges I faced

It's easy to feel overwhelmed in testing. There are so many different approaches and classifications of tests... it can all feel like too much to learn. It's vital to remember that poorly organized or classified tests are way better than no tests, so just start!

Key takeaways

Test driven development is extremely good at helping one break tasks into tiny, digestible pieces. If I need to create a brand new page within an application, I tend to focus early on the most complex part. Taking a test driven development approach, the first step quickly becomes writing a failing test which checks to see if the URI exists in the application. This forces me to think critically about what that URI should be. What is the appropriate name for this? What are the relevant parameters? Does it reasonably fit a resourceful routing model? The answers to these questions quickly influence better decisions being made as work continues.

Tips and advice

If you are completely new to testing, try to get started by learning about testing environments for your preferred language. Write one or two basic tests. Something as simple as checking if a URI returns a 200 response is a very valuable start. The rest can come iteratively.

If you already have experience testing but don't stick to it, make an effort to write a test before the code which satisfies it a few times a week, and reflect on how it impacted your workflow.

Final thoughts and next steps

Test Driven Development is a different paradigm, and might require some big changes to your workflow. However, the work tends to pay off throughout the development process, and beyond as a suite of tests help ensure nothing has broken or changed unexpectedly in that area.

Discover and read more posts from James P Clark
get started
post commentsBe the first to share your opinion
Show more replies