Saturday, August 31, 2019

Great experience using TDD this week

I had a great experience with using TDD (Test Driven Development) to implement a new feature this week while at a customer site. I started by going into the location the code would need to execute. I did this to gather available information that would be needed for the feature.

I felt like what I was adding was easy enough in my mind and started, by habit, writing in a solution in spot. I stopped and thought back on an experience the week before where I was able to use a new function to improve old code. I reset my file (using git) and set up a new test environment instead.

In this development environment, I write my code in Structured Text (IEC 61131-3 standard) and my tests have to be written in c. So I started with a test that couldn't compile and then added the function it was calling without any behavior. I did only what I needed to get to green until I had all of the tests in my inbox (as J.B. Rainsberger teaches in his World's Best Intro to TDD Course:

I was able to write it test first and do final integration tests by hand in simulation before every putting the change on their machine.

I installed and ran it with confidence while the customer watched. I had no doubts when we ran off the first part to his specifications.

In the past I would've had something ready to test sooner but would've had to debug it in front of the customer. I would've ended up adding to the section of code with a procedural solution instead of having a few useful functions .

It felt slower up front but the confidence it gave me when I was ready to install it on the machine was fantastic. I suspect it would've taken at least as long if I'd done it on the machine but it would've taken time away from the operator being able to run the machine while I was working it out. So I'd say this was a force multiplier as it gives the customer confidence to see that we can make a change confidently.

No comments:

Post a Comment