Showing posts with label legacy. Show all posts
Showing posts with label legacy. Show all posts

@since Sunday, January 9, 2011

Unit Testing Principals and Coding Kata

@throws 1 exception(s)
For the past few weeks I've been trying real hard to teach unit testing principles to my development group. Thinking on the subject I decided to create a workshop for the group to actually practice writing unit tests. Luckily, my managers gave me the approval and opportunity to spend a decent amount of time on creating a lecture and coding workshop for the subject. 


The following is the lecture I presented to the group last week. The presentation was accompanied by explanations and examples from the group day-to-day tasks. Most of the ideas and axioms presented were collected from books I read to better understand and improve my software craftsmanship skills. Primary books dealing with unit testing and tests in general are: Clean Code by Robert C. Martin, Working Effectively with Legacy Code by Michael Feathers, Refactoring: Improving the Design of Existing Code by Martin Fowler, Kent Beck, John Brant, William Opdyke and Don Robert. I've also covered few topics presented in blog posts from the hacker chick blog [1, 2] and Martin Fowler blog [1] (thank you, Uri).

coding Kata was created to illustrate a small code base (legacy as it has no unit tests) of bank account operations. The logic, of course, doesn't really makes sense, but I used all the elements and principals most developers will encounter during their daily development tasks (Entity, DI, DAO, etc.). I've included a sample unit test for the PromotionService class so developers can learn by example when trying to write other tests. The Kata practices writing mock enabled unit tests using EasyMock focusing on IMocksControl and Capture scenarios. Some test cases were offering the option of using of EasyMock's nice mock (as a simple stub) or practicing strict mock of recording behavioral order.

The workshop took almost 3 hours to complete. Still waiting to get some additional feedback from the participants but so far all are positive ones. From what I managed to hear, people are discussing the topic and concepts I presented and I hope they will eventually agree with most issues. I have no doubt that I will keep having argues on the subject, but hopefully less than before (well, I can dream, right?).