Apex DMIT Interview Question

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