Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write Unit test during development? [closed]

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?

like image 966
xjsXjtu Avatar asked Jan 18 '26 22:01

xjsXjtu


1 Answers

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.

like image 194
BЈовић Avatar answered Jan 20 '26 14:01

BЈовић