3 ms·
>Although Given-When-Then is a fantastic way to describe interactions, state and behaviour, it is a lousy way to describe data and calculations. I follow a sli
by pytester 8y ago
>Although Given-When-Then is a fantastic way to describe interactions, state and behaviour, it is a lousy way to describe data and calculations.
I follow a slightly different technique that I think makes
given/when/then also a useful tool for describing data and calculations.
1) Write the test as follows, using deliberately simplified but still realistic data (this is crucial):
>Given <a set of market data and trades in a table>
>When <arbitrary event such as calculation is performed>
>Then <leave blank>
2) Write the code that outputs the data/calculation.
3) Run the test in a "rewrite" mode that fills in the results of Then based upon actual output (this process is somewhat similar to golden master).
4) You now have a passing test and generated data which you can eyeball to see if it is in line with what you would expect. This test with recorded output can then be shown to the PO (or whomever) and committed to source control and used for regression testing.
This obviously isn't possible with cucumber or other gherkiny tools and it does require your processes to be fully deterministic (a laudable goal anyway), but it works pretty well IMHO.
- delusional 8y agoThat's a pretty common technique. The problem I've found is that it risks incorrect results be assumed correct. If I refactor your algorithm, and fix a bug in the process, I'll be very confused if your tests start failing. The benefit of calculating it yourself first is obvious, you get to cross check your result. That tends to highlight minor errors such as -/+ errors. This is not a problem if stability is more important than correctness of course, but that's not where I am.