Denis' Micro Blog

Welcome! 👋

Design | Development | General
Guides | Life | Tips

Self-Testing your way around...

July 4, 2023 | Development

Good day, good day.

Hope you are doing well on this beautiful day. ❤️

Well... If you're a developer, you might recognize this scenario.
You finished up your piece of code. (Or you haven't even started yet, for all of you TDD freaks... 😝)
And then you really wanna rather do the "real programming". But then you gotta write tests.
Sometimes it feels good/needed. Sometimes not so much though, mainly due to its monotonousness. I think you get what I mean. 😅😂

Okay. But can we stop this entirely? No? Okay. Can we at least mitigate it? Sure. That's more doable. Well. Let's just make it "self-testing". What does that mean?

That term just states that your production code contains measures, which test different most of the time impossible to achieve, states of objects.

That could be stuff like assertions, where you assert a set of pre-conditions before it is executed. Or technically even full-on tests inside your production code. Would I recommend that one compared to having them separated though? Ehrm... Nah.

Why? I mean. This is kinda debatable, but I'd argue with the argument of the "separation of concerns" principle. And why shouldn't it count for the test code as well?

Meanwhile, assertions simply verify and enforce the allowed states of a certain piece of code.

This way, we can assure that everything is working on runtime. Even if you got performance problems, most of the time you can turn off the assertions automatically inside the production version, for example.

This is what I meant with, it can only help with your testing needs.
While it almost certainly reduces the number of bugs you encounter, it also helps you with having the confidence to make changes in your production code. If everything still runs and doesn't crash, in this case, if your test suite is complete. Well. It is working correctly.


I don't have to tell you that this is pretty good since oftentimes new bugs get created while adding stuff on pre-existing stuff.
So yeah. That concept of self-testing code is pretty neat to use for those advantages alone. Use it? Use it not? Your decision. But it would be a good idea, according to this basic blog post, at least.

See ya.