Significance of existence of unit test (self-discussion)

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?

Reasons to do unit tests

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.

Why do you do it?

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

Significance of existence of unit test (self-discussion)
Automatic creation of Java unit test result report
Json Request in Unit Test of Controller using MockMvc
[Java] Significance of serialVersionUID
Java Unit Test Library-Artery-Sample
Unit test with Junit.
[IntelliJ IDEA] Perform Unit Test
Introduction to Micronaut 2 ~ Unit test ~
Unit test architecture using ArchUnit
I checked the automatic unit test creation tool (end of 2019 version)