Unit testing - how do I test a function that returns random output?

后端 未结 6 821
半阙折子戏
半阙折子戏 2020-12-07 01:01

I have a function which takes in two parameters, and returns one or the other 50% of the time.

The unit test for this should determine that both parameters could be

6条回答
  •  离开以前
    2020-12-07 01:12

    If the randomness is based on a random number generator that it calls, you can rig up a stub random() function that returns various results to give you your expected outputs.

提交回复
热议问题