Unit Tests
October 14, 2010 at 9:45 am Leave a comment
Introduction
A while back I added an article on EasyMock and since then I have gained some more insight into Unit Tests.
During this period the importance and benefits of unit tests have been highlighted to me in practice.
A Senior Developer gave me two good phrases (actually they came from two Senior Developers)
1. A good unit test is if one line of code is changed atleast one unit test fails.
2. If your unit test becomes quite complicated, it is a sure sign that your method is too complicated.
What are Unit Tests?
During my graduate and post graduate studies the emphasis on testing, let alone unit testing was very minimal. In the working world at times this is also left out / reduced due to time / budgeting constraints.
To me a unit test is a test that tests one way the method could be executed.
Benefits
So we have a unit test (a method that tests our method) , this brings about two benefits:
1. Ensures method does what we expect it to do
2. Ensures that if we make changes to the method, it still does what we expect it to do. If it does not we have to fix it by either updating the method or the unit test itself to cater for the new requirement.
Summary
As a Java Developer, developing both the front end (using ICEfaces ) and back-end writing unit tests for these types vary. Back-end code usually requires the mocking of the database whilst front-end requires mocking of these business services. Yes they might seem a bit different but the aim is the same.
I would like to actually discuss more of the benefits as it has come to me in several ways over the past weeks after we began intensifying our campaign on increasing the amount of unit tests we write per method. In a modular section based team, where one group is responsible for the front-end, other back-end (could be split up) can cause the one team to wait on the other. Resulting in the possible loss of revenue, however if good unit tests are created per development team, the other can go on and be 90% sure their code is correct and reduce the time they need to go back and fix things as well as not be held up.
Ok that was just some of my points on Unit tests, will have some more, with Java examples soon.
Blog Soon!
Entry filed under: Uncategorized. Tags: .
Trackback this post | Subscribe to the comments via RSS Feed