Test factories that reveal intention

Posted by Rod Caldas on November 28, 2016

Recently by the same author:


Going to QCon this year

I’ve been creating test factories and I always think they are hard to read. Recently I have been reading a book called Growing Object-Oriented Software Guided by Tests. This gave me the idea of applying the Builder pattern to my test factory itself. Now was this a good idea or am I over complicating this? See for yourself and decide.

Below is my test case factory built with the Builder pattern:

Below is an example of an execution of this factory:

test factory example

Now should I use the Builder pattern in every test factory? Probably not but when dealing with creating complex objects it is definitely a good idea.