Posts

Showing posts from 2014

Test Driven Development with Alfresco - Part 3 Test Doubles

So far in this series I have given an overview of Test Driven Development and briefly described Inversion of Control.  Proper unit testing requires testing a unit in isolation of its dependencies.  The only thing you care about in relation to a unit's dependencies is how the unit interacts with those dependencies not so much what those dependencies do.  Inversion of Control (IoC) allows us to separate the creation of dependencies from the unit itself but we still need to inject something into our units that we can use for each dependencies.  This is where test doubles come in.  A test double takes the place of an actual dependency. Types of Test Doubles There are a lot of different opinions on what test doubles are but the most commonly accepted standard would be from Gerard Meszaros book xUnit Test Patterns: Refactoring Test Code (Addison-Wesley).  These are: Dummy Doesn't do anything and returns null, zero, or the return types nearest equivalent.  Essentially a dummy d

Test Driven Development with Alfresco - Part 2 Inversion of Control

In my last post I briefly described the process of TDD.  In that discussion I stated that a unit test will test in isolation; meaning that you don't want to test a unit's dependencies only the unit itself.  In the real world our code doesn't run in isolation, in the real world our code has dependencies.  I also stated that in a future post I would talk about test doubles, however before I can talk about that we need to discuss how we isolate our class from the world around it.  Of course we can't isolate it completely, a completely isolated class is generally useless, but we can decrease the dependencies.  This dependency on other classes is referred to as coupling and coupling is generally considered bad. An excellent way to reduce coupling is called inversion of control, which is also referred to as dependency injection.  Many people when they think of inversion of control think of frameworks such as Spring, JUICE, or Java EE.  Although these frameworks offer invers

Test Driven Development with Alfresco - Part 1 Introduction to TDD

This is the first in what I hope to be a series of blog posts on Test Driven Development (TDD) with Alfresco.  Before I can jump into the topic I want to make sure we are all on the same page with TDD.  I have heard a lot of definitions of TDD (primarily from interview candidates that haven't actually done TDD) and I know there is a lot of confusion as to what TDD is. Unit Testing Before I dive into TDD I want to talk a little bit about unit testing.  There are different types of testing, unit testing, integration testing, and system testing (there are others but all of them are out of scope of this blog except unit testing anyway :)).  Unit testing is the testing of a unit in isolation.  A unit of code in Java is generally a class.  The idea is that you are only testing the unit not the unit's dependencies (we will explore test doubles in a future post, for now just know there are ways to isolate your unit from its dependencies). With unit testing there are two sets of so