Reputation: 17749
Unit testing is, roughly speaking, testing bits of your code in isolation with test code. The immediate advantages that come to mind are:
- Running the tests becomes automate-able and repeatable
- You can test at a much more granular level than point-and-click testing via a GUI
My question is, what are the current "best practices" in terms of tools as well as when and where to use unit testing as part of your daily coding?
Lets try to be somewhat language agnostic and cover all the bases.
Upvotes: 25
Views: 6680
Reputation: 29657
Ok here's some best practices from some one who doesn't unit test as much as he should...cough.
Upvotes: 22
Reputation: 3934
Don't forget refactoring support. ReSharper on .NET provides automatic refactoring and quick fixes for missing code. That means if you write a call to something that does not exist, ReSharper will ask if you want to create the missing piece.
Upvotes: 0
Reputation: 95482
You might want to look at TDD on Three Index Cards and Three Index Cards to Easily Remember the Essence of Test-Driven Development:
Card #1. Uncle Bob’s Three Laws
Card #2: FIRST Principles
Card #3: Core of TDD
Upvotes: 14
Reputation: 48923
NUnit is a good tool for any of the .NET languages.
Unit tests can be used in a number of ways:
Upvotes: 0
Reputation: 1386
A great resource for 'best practices' is the Google Testing Blog, for example a recent post on Writing Testable Code is a fantastic resource. Specifically their 'Testing on the Toilet' series weekly posts are great for posting around your cube, or toilet, so you can always be thinking about testing.
Upvotes: 3
Reputation: 994371
The so-called xUnit framework is widely used. It was originally developed for Smalltalk as SUnit, evolved into JUnit for Java, and now has many other implementations such as NUnit for .Net. It's almost a de facto standard - if you say you're using unit tests, a majority of other developers will assume you mean xUnit or similar.
Upvotes: 3
Reputation: 1889
The xUnit family are the mainstay of unit testing. They are integrated into the likes of Netbeans, Eclipse and many other IDEs. They offer a simple, structured solution to unit testing.
One thing I always try and do when writing a test is to minimise external code usage. By that I mean: I try to minimise the setup and teardown code for the test as much as possible and try to avoid using other modules/code blocks as much as possible. Well-written modular code shouldn't require too much external code in it's setup and teardown.
Upvotes: 1