Unit test is good for maintaining a software, especially if the maintainer is not very familiar with the whole system.
But I have a question here:
Before I complete the whole software system, how should I determine which functions I need write unit test for? In other word, what's the best granularity for unit test?
What's worse, The name or functionality of tested functions may be changed during the develop process or after time-to-time refactors, how should I maintain the unit test?
how should I determine which functions I need write unit test for?
It is simple : try to unit test whatever you can, and try to get the unit tests coverage as high as possible. Of course, some things is not possible to unit test (access to specific HW, or DB) and some things should not be unit tested (functionality of an 3rd party library).
what's the best granularity for unit test?
As said, try to have unit tests coverage as high as possible. Higher= better.
The name or functionality of tested functions may be changed during the develop process or after time-to-time refactors, how should I maintain the unit test?
Treat unit tests as part of your code, and maintain them with the code. When the code change, change unit tests (modify, add and remove what is needed) to make them pass, and if possible increase unit tests coverage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With