2 ms·
How I often approach this is to 1) write a couple of unit tests 2) refactor unit tests into data-driven tests, using pytest.mark.parametrize 3) use hypothesis t
by jononor 8y ago
How I often approach this is to 1) write a couple of unit tests 2) refactor unit tests into data-driven tests, using pytest.mark.parametrize 3) use hypothesis to generate the data. I very often get to 2, but not always to 3.
The most basic things to check
- No valid inputs give an error
- All invalid inputs give a error
These are enhanced if you sprinkle your code with assertions. Writing assertions inside the code is good training to identify. Something supposed always non-negative, check it. Something always supposed to have more than 0 entries, check it. Something supposed to be sorted, check a[0] <= a[1] and a[-2] <= a[-1].
Often you can test symmetry type properties
- deserialize(serialize(in)) == in.
- init(); connect(); disconnect(); -> state identical as just init();
Or you can use an 'oracle', something external that tells you whether the output is correct or not.
- allTricksOptimized(in) == simpleReferenceImplementation(in)
- myImplementation(in) == thirdparty.implementation(in)
- sametmax 8y agoThanks. felixyz links did contains all those, but I'll remember the trick about pytest.mark.parametrize as a step toward hypothesis.