1. 2
  1. 1

    Though this article relates to Django specifically, the Python mocking libraries factory_boy and faker seems relevant and useful for other situations that may benefit from realistic test data.

    1. 1

      I would advise against using random generated data inside tests but use reproducible generated data instead. Example email generator: test + counter + @email.com.

      Random generated data might make tests flaky, and we even reached a point where random generated data produced same email and incorrectly caused tests to fail.

      1. 1

        OTOH, random data can help you uncover more bugs, provided you know what (random) data your tests failed on. I’ve been using mimesis and so far I can recommend it.

        1. 1

          You might like QuickCheck; it’s been ported to many languages. It’s random but reproducible (give it a seed to replay a specific run), and it has generators for specific types that test edge cases that a home-grown data generator wouldn’t. You can also write your own generators, e.g. one that makes sure email addresses are unique (I’ve had to do this one a few times).