Join the discussion…


  • in this conversation
      • As an aside I personally I don't think there is much justification for duplication in unit tests. Tests should be refactored just like production code to ensure that they are maintainable as possible. The advantage of using the builder is that if how you construct the object changes then you only have to fix the builder and not hundreds of tests. Builders really do make it a joy to test.

        • Using [atomic]sequences to set default value is an interesting idea i'd experimented with.
          Now in your particular example, I might be wrong but it's possible to end up with clubs of unrealistic number and loft (a few bags containing 2 or 3 clubs and you're done), which, imho decreases the quality of your data, which have an impact on the quality of your tests. Am I wrong ?

            • The example above is a little contrived but, until the code you are testing has logic regarding the number of clubs in a bag and valid clubs' lofts, then test data does not need to be real. I would not want to spend too much time setting up real data if it was not required. Obviously for this domain it would not not take long before logic is added so you would need to refactor the test data; thankfully it would only be in one place. A BoundedSequence could be used to generate more realistic data. For example, BoundedSequence.anIntegerSequenceFrom(1, 9) for club number generation.