Skip to main content

Posts

Showing posts from May, 2012

Achieving more Isolated Unit Testing

Good unit tests should be:fastindependentwell focusedisolatedIf your unit tests are slow, you're not gonna run them as often as you should. Therefore one of the main benefits of unit testing is lost - the lack of instant feedback.Each of your unit tests should be independent. The order in which you run your tests should not matter. By keeping your tests focused you should be able to refactor, add new code and not have the majority of your tests fail. If you change class A, you would expect class A's tests to fail at worst. If other tests outside of this scope fail, your tests are not focused enough. This lack of focus leads on to isolation.Tests should be isolated from other dependencies. Dependencies such as other classes should not affect each other, providing the contract between the code is maintained. Likewise the file system, the web and databases should not be involved anywhere with your unit tests. If any of these dependencies come into play…