Apex DMIT interview question

How do you do unit testing? And why It's needed?