First of all, I'd suggest reading on the subject as this forum is quite limited in this regard. You could read books on unit testing. I don't have the time to write a whole book here. :D
Anyway, here is the Wikipedia page on unit testing. Check it out, it has examples too.
If you've read that, please ask away for specific questions. It would also help if you'd specify what code language would you like to use for testing as different languages have different frameworks and flavours for testing.
Good luck!