I am manually creating a rather large data model as input to my unit tests. Data model is created using a number of builders. Developers use these builders in order to create the data model as they see fit for a particular unit test.
An example might be in order: when reporting work time, it is possible to report taking a break. This break must be within the working hours, no sense in taking a break at midnight if you worked a 9am-5pm shift.
I have kept from validating any of the inputs into the builders, because:
- I believe developers should be familiar with data they create.
- Makes the builders more complex. Testing infrastructure should be as simple as possible, in my opinion.
Of course, this means the developer can make a mistake and create a break that is outside of the working hours.
A colleague of mine proposed I do some validation, e.g. making sure the break falls into the working day. It is a minor change and introducing it won't complicate things, but it got me thinking.
Is it a smart move to validate input data for your unit tests, and what are the drawbacks here?
addValidBreakTime()
oraddInvalidBreakTime()
. This would extend the testing language available to the people writing unit tests. – BobDalgleish Mar 29 '19 at 19:19