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
Rytmis
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.
But, being a white box software testing technique, unit testing is an in-depth process that requires a lot of knowledge about the code and how it interacts with other parts of the project. As a result, it can be hard to start writing unit tests, especially if you are new to the codebase.
They told me to learn unit testing and write unit tests for a project that has 3000 lines and 35 classes approximately in 3 weeks. I did read Art of Unit Testing in 2 days and getting used to unit tests took another day already.
Developers experience Unit Testing as difficult when they run into these kinds of problems: Classes are tightly coupled to other classes, which makes it hard to test because you need to control those other classes as well when you are writing your tests. This is very, very difficult and very error prone.
Ok here's some best practices from some one who doesn't unit test as much as he should...cough.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With