- I was thinking, WT* is the unit test?
- Why should I need unit test?
- Why should I spend my time to prepare the test cases?
- Why should I spend my time to become a tester instead of a developer?
For the first question, if searching online, what you get are just bunch of almost useless information. They can let you get high score in exam.
For the second question, instead of answering why, I will say, it depends. It depends on the language you are using and the framework that you are using. Let’s say you are working on C programming, there is less support of unit testing library. If you are working on Linux kernel development, unit test is difficult to implement. But, if you are developing web application, then unit testing and other testings are highly recommended. Why? Let me go to the next two answers beforehand.
For the 3rd and 4th questions, if you are not a tester, you no need spend your time specifically to prepare the test case. But, since you are a developer, surely you need to test your function during the development. Then, that is the time you prepare your test cases.
Why do you need “testing”?
Because of the advance of the web applications, the faster web development is needed. That is why there are so many MVC frameworks. But, faster development does not guarantee stable and valid products. In order to make it stable and valid (do what I want), you need to test it.
Since I was developing command-line tools, C/C++ libraries, scripting, desktop application using GUI widgets like GTK+/GTKMM, they are less likely to be tested as MVC. For example, if you are writing a linear function, y=mx+c, are you going to write a test case on it? Surely no. You can write a test case, but it is insignificant to see the advantage of unit testing. Because it is too simple. Nevertheless, if you insist to write the test cases, then you can include the test cases with non numerical input parameters, numerical input parameters, etc. However, since you are not a tester, but a developer, surely you can ignore this kind of testings.
Now, interesting part is writing the test cases. Once we write the test cases, then we can test these cases in automation. This is the part I like most. When you do the testing, it will go through all the test cases you have written. This means that, we can get the bugs when we do the development and testing. Since the web application involves so many components, we will break the functionality easily when we add some features. By adding new functions, we modify the old function, and accidentally break the old functions. Without using automated testing, we will prone to test the new functions only, because we “knew” that, old functions work.
So, using unit test and integration test, we can make sure that our product passes all the test cases. And we are confident that our product is not just being tested with the latest function, but the existing functions are still working.