Introduction to unit testing and its importance

While testing is absolute necessary in application development, many novice developers get away with a few basic questions regarding testing. They are:

  • What is unit testing? and why is it a developer's job?
  • Why is unit testing so important?
  • And, do we need to write unit tests for each section of our programs?

We will start this chapter by answering these basic questions. If you would like to rather start with testing using RxKotlin directly, you can skip the first few sections in this chapter and start from Testing tools in RxKotlin. Though I would encourage you to read the chapter throughout, even if you have previous experience in testing with Kotlin.

Let's start by defining unit testing. Unit testing is a level of software testing where  the individual smallest testable components of a software (aka application), called units are tested. The purpose is to validate that each unit of the software performs as it was supposed to.

Unit tests can be done manually, but they are often automated. The sole purpose of automated unit testing is to reduce human error and eliminate any extra bugs/errors caused by them. To explain let's first remember the proverb:

To err is human

So, if we do the unit tests manually, the chances of additional errors or bugs will rise. Automated unit tests can eliminate this risk as they include minimal human effort.

Also, we need to document the tests we've performed, and we need to perform the same tests again with new ones with each incremental build of our product. Automated unit tests eliminate that extra effort, as you would be required to write the test once and then you can run them any time in the future. Also, automated unit tests also reduce documentation efforts.

Why is it a developer's job? Who would write the code for automated testing other than the developers?

Also, it is not possible for developers to give understanding to tester after completing each small units of an application. Even you may have completed some module, which is not yet on the GUI, so the tester or anyone else than you may not even be able to reach that unit to test. Also, it may not have any direct impact or relation with the UI/UX, it may be a small internal code part.

To summarize, a developer better understands his code and he knows well what exactly he wants from that bunch of code. So the developer is the best person to write unit tests on that module.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.123.34