hi,
i am having a
unit test, which uses a list of objects as test data.
i am testing that this list forces a method to be called a certain amount of times depending on the list's size and objects type inside the list. i am using a mocks to isolate my class.
because i want to have random objects in this list i am calling a build method which generates a certain number of fixed objects whose type is depending on a int return value of a random function.
now my question:
is it alright if some randomness is included in my test data or should it be avoided at any time?
pros:
-i use random (in my case realistic) test data.
cons:
-a failing test is very difficult (or even impossible) to reproduce.
-unit tests shouldn't be dynamic, running them once or thousand times must show the same results, which is not 100% sure if test data can change during different test runs
of course i would use only random data in very rare cicumstances! but i thought it my case useful, because it is very time consuming and annoying to generate a good mixed and big list in my test suite.
maybe the solution to my problem could be a little code generater and copy/paste it into my tests...
thanks for your thoughts.