Hi folks,
I have just written a handful of
Unit Tests that test the processing of an external data feed coming from some remote system over Http. In order to isolate myself from the remote system I have injected a Test Double that looks up some tabular data from a local CSV file instead so that I have control over the input data and am not reliant on the availability of this external system. This works fine.
However, upon review I have realised that my tests are exhibiting a readability smell that Lasse Koskela refers to as "Split Logic" (in his most excellent book "Effective Unit Testing"). The problem is that the information relating to the test is split between the test case itself and the CSV file which makes it difficult to determine what the test is actually doing. As the data sets are expected to be very small, just a handful of rows, I would like to inline the data.
I am currently on the road to addressing this issue and have written a new Test Fake class that I can load up with some pre-defined data from my test case. I am now defining my dataset in the test case, which is what I wanted, but the format of loading up Lists with the data is really ugly and I have been unable to find a way to represent the data in a way that makes the test methods naturally readable.
Has anybody run into this sort of problem before who may be able to give me some suggestions on how to represent my data in
Java while retaining the visually tabular format to keep my tests readable?
Thanks
Tim