re: Writing Good Unit Tests: A Step By Step Tutorial VIEW POST

re: I am struggling a bit to apply property-based testing in this case. Can you give me an example, please?

All the random tests with {lat, lon} ∈ {[-90, 90], [-180, 180]} should pass returning a value that is less than 20K km approx.
All the random tests with {lat, lon} not in the range above should pass returning a meaningful error.
Then you run N tests with a proper latlon, manually check values, record a seed and re-run tests after with the same seed.

Thank you for the example. This seems like a great "casting net" for all sorts of general bugs and problems.

Still, I'd add some manually-written tests on top of these. I wouldn't rely on randomised tests more than I would rely on my domain knowledge. For example, a set of randomised tests wouldn't be able to "tell" you about problems you might experience around 180th meridian or around poles. They don't know the reason behind these problems. A human, on the other hand, is able to (re)read the requirements, think critically and figure out all sorts of problems using a creative systematic approach.

code of conduct - report abuse