What is unit testing (unittest)?
UnitTest is to check whether the result of a function's return or its effect on system data is consistent with what we expected.
Second, why use unit test?
1> guarantee the correctness of the function. If this function is called by the upper code without guaranteeing the correct situation, then as the project is deepened, the level of calls becomes more and more, which leads to unnecessary bugs, increases the difficulty of development and reduces the efficiency.
2> reduces the workload of developers, making it easy for developers to develop.
Third, is the Unit test necessary?
1> How much time does it take to debug the code we write?
Writing the unit test allows us to quickly find out the problem with the function, while also helping us debug the code for easy debugging.
2> you think your current code is right, but it is likely that there are a lot of pitfalls in the system, will you take the time to find these pitfalls?
Writing unit test allows us to find some potential pitfalls in the system.
3> for a new bug, how long did it take you to position the bug in the code?
Writing unit test can help us quickly locate some bug locations in the code.
Summarize:
As the project progresses, your functions will be called deeper, and in case of special circumstances, you will spend a lot of time and effort to solve the problem, the appropriate unit tests can greatly reduce your workload and make your work easier!
Finally, make a good habit of writing unit test.
Introduction to Unit Test UnitTest