Hello.
I think many people write unit tests when they are engineers. In my past experience, I wrote about 80% of the projects. But why do I have to write it?
When I analyzed it in my own way, I got the following opinions. ① I was told to do it ② To use as an index number for personal goals ③ For quality improvement
I'm sure my boss told me about ①. However, the thoughts of bosses who do not understand why they do it are generally summarized in (2) or (3).
② is a quick way to make numbers. However, it is a meaningless number because you have to write a test for such code as well.
sample.java
public int returnZero(){
return 0;
}
Regarding (3), quality is not only code but also performance and specifications, so writing a unit test does not mean that quality will be improved.
I feel that it is not worth doing if you put it together like this.
So why go back to the beginning and do it?
Your own answer is ** "to gain confidence and peace of mind" **.
You're writing the source code, and you'll get what you expect to see, right? You may be worried about that, but you can check the result by writing a unit test.
Also, in the future, if there is an implementation that has the same result but different processing content, you can check the result immediately by writing a unit test.
With the execution results obtained so far, you will be confident! You can say that.
So I'm special so I don't need a test! You don't have to write it separately, just stay as you are.
If you don't, why not write a unit test to give yourself some leeway?
Recommended Posts