#TIL: SimplyTestData

Jul 22nd, 2014

While browsing / playing in some other teams’ projects in our company, I stumbled across a neat construct that I hadn’t seen before in unit tests – Simply Test Data. Using this framework you can construct some fake objects in a fluent and easy to read manner.

Similar to other fake data frameworks like NBuilder, this framework allows you to define methods you can reuse to create and manipulate test objects to be used in your unit tests. The fluent, expressive interface makes your tests easy to read and understand, helping other developers figure out what’s going on. Here’s a quick example:

Here we’re returning Actions, which allow us to chain these little helper methods together to build the test object we want. Now any time we want to make Greeting objects, we can use these few methods in an expressive way in all of our tests.

What if you always want to apply the same transformation every time you create the same type of object? We’ve got you covered!