I am writing test cases in JavaScript at the moment. One typical scenario I have come across is:
- Read a text string from a web browser (this string is dependent on a block of json code)
- Compare this text string read from step 1 against a hard-coded reference, which is the same expected string
- If the string read from step 1 is identical to the hard-coded string, it is a pass; it is a failure otherwise.
I am personally against this approach, as for each test execution, we literally bash subject under test against the same wall. There is little value of doing it. What I have in mind is:
- Randomize the string by injecting different json each time
- Record the expected string by reading json
- Read the string from a browser window
- If the string read from step 3 is identical to the string recorded from step 2, it is a pass otherwise it is not.
Overtime, the second approach will test a larger spectrum of strings instead of a static string.
But, as rule of thumb, there has to be a trade off somewhere. Can anyone see the downsides of the second approach, comparing against the first one?