Reputation: 733
I've never really written unit tests before (or tests, for that matter, really). I tend to obsessively run/compile after writing even the smallest bit of code to check for errors. I've been doing a bit of reading up on unit tests lately, and I'm curious how to best go about using/implementing them. My main language as of late has been Python, but I think this is a pretty language agnostic question. Does anyone have some tips (or good reading) on how to do this properly?
Thanks!
Upvotes: 5
Views: 422
Reputation: 4060
An open source utility library that I use when writing Unit Tests is ApprovalTests - there is also a YouTube video series on how to use this library with .Net languages (the ideas can be applied to other languages and the ApprovalTests library is available for other langauges (Java, PHP, more) as well.
Upvotes: 0
Reputation: 2668
I would strongly suggest using a framework such as nose which is built on unittest and follows the same principles but takes much of the scaffolding out of the way for you.
Upvotes: 0
Reputation: 5074
Unit testing is one thing, another thing to consider is test driven development, where the act of writing the tests first affects the design/ feel of the finally delivered code - hopefully for the better. I find this helps especially if the problem domain is not fully understood at the start of programming.
Clarke Ching does a good one hour talk about TDD using excel. If you spend an hour reading through this, you should get the idea.
http://www.clarkeching.com/files/tdd_for_managers_and_nonprogrammers_using_excell_and_vba_final.pdf
You know you have arrived with unit testing when xUnit Test Patterns is an enjoyable read. http://www.amazon.co.uk/xUnit-Test-Patterns-Refactoring-Signature/dp/0131495054/ref=sr_1_1?ie=UTF8&qid=1288638075&sr=8-1
That is probably a big ask initially though, and I would suggest something thinner about either refactoring or TDD would be a more gentle introduction to this fascinating subject.
Upvotes: 2
Reputation: 6654
I like this one: The Art of Unit Testing. The examples are in .Net, but that should not be a problem. I don't know any book with examples in Python.
Upvotes: 1