Improve Your Testing #9: Learn From Testing Mistakes

We often don’t manage to make well-designed code on the first try; therefore, it’s essential to learn how to fix it. And why!

David Rodenas PhD

--

“A boo-boo in your code? Let’s fix it” — Prompted by the Author.

In the previous article, I presented the “secret recipe” to convert an arbitrary complex test into a simple one easy to read. But I have to confess something, in order to make a quick example for the article, I asked Claude.AI to generate one. And you know what? The generated example was wrong! But wait, it wasn’t wrong because it didn’t work, it was wrong because it was a bad design!

For the previous article, I fixed the design and I presented it. But, giving a little thought, I believe that it is interesting to show the errors that Claude.AI made. After all, Claude.AI has been trained on real code. So, the design errors found are likely present in many other places. That is why I’ll show you the wrong code, why it was wrong, and how I fixed it.

Starting Point

The whole process begins with a test code, the typical one we might encounter, which is long and difficult to read. It might be simple to write, but at a glance, we can’t tell what it does. As an example, I used a test code for a React component. The code was like this:

--

--

David Rodenas PhD
David Rodenas PhD

Written by David Rodenas PhD

Passionate software engineer & storyteller. Sharing knowledge to advance our skills. Join me on a journey of discovery in the world of software engineering.

Responses (1)