Wednesday, May 29, 2019

TDD: Where Did I Get It Wrong?

If you are developing using Test-Driven Development (TDD), there is a chance that you are doing it the wrong way. The symptoms of this are very clear. If you have a huge test suite that breaks every time you insert a new feature or make a change to the code, and you end up having to rewrite tests to make it pass again, you are there. We've all been there, and sometimes we still are.

I was blown away by this presentation from Ian Cooper on DevTernity asking where did all go wrong with TDD. The catch was that at some point, we started to focus our tests on methods instead of focusing on features, on scenarios. To return the TDD to its track, Behavior-Driven Devlopment (BDD) was created. Actually, according to Ian, BDD is how TDD was supposed to be. All of these GIVEN, WHEN, THEN help us think about scenarios and stop thinking about methods.

Image title

So let's try an example, developing using the correct TDD way. Let's suppose we have a part of our system that is responsible for keeping historical records of products and services sold. We want to save a record and retrieve a list of all the historical records. Given the "HistoricalRecord" below, let's build our "HystoricalRecordController."



from DZone.com Feed http://bit.ly/2XaBXAF

No comments:

Post a Comment