Software Testing — Started from my personal doubt

What is it for?
To increase your confidence level on production release/deployment.

What should I test?
All, yes all code blocks (100% code coverage).

What is the best way to learn Unit Test?
This is my personal journey, I learned unit-test from math.Pow built-in Golang function. Test file can be found here, on func TestPow(t *testing.T) test case exactly.

Tried to cover all codes,
Tried to write a code block that starts from the main function that instantiates HTTP server, instrumentation kinds of stuff, instantiating handlers, instantiating services, and repositories, and… found out that it’s near impossible to test all of them, should I create more interface and mock them all?
Big No, 100% test coverage is a lie. You don’t need to.

Again, should I cover all codes?
Ideally yes, but software engineering has a ‘bit’ difficulty to achieve that one.
That’s fine to not achieve 100% code coverage, as long as your Unit Test increases your confidence level on production deployment.

After creating Unit Test, my test file getting longer than the code that I test, is it okay?
Yes, of course, along the time, your test code could be longer than the code that you test.

I did, accomplish 85% code coverage, but there is a PostgreSQL query and Redis command that can’t be really tested, what should I do?
Really want to increase more coverage? if yes, it’s time to add an Integration Test that should spin up PostgreSQL and Redis on a container locally. Of course, we can utilize any Containerisation technology nowadays.

I did, accomplish 90% code coverage, but I’m not confident enough with production deployment, why?
This means that your Unit Test is not comprehensive enough.
Instead of pursuing higher code coverage, making a comprehensive Unit Test is more than enough.

I did, accomplish some 90% code coverage, but I still discovered a new bug on production, shouldn’t be Unit Test prevent this?
No, Unit Test is not a guarantee, but a guard, once you have a new bug means that it’s not covered so please add a test case that covers the bug.

I did, added test cases once a bug was discovered, but still, discovered a bug for kinda edge cases, what should I do?
Aha, Now’s time to continue to the next stage, providing an End to End Test then. That’s all the journey of Software Testing.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store