Software Testing & QA (50 Qs)•Part 3: Advanced Internals, Scale & Production Quality (Senior / Lead)
Property-Based Testing: Fuzzing algorithms with fast-check to discover hidden edge cases.
senior LevelCode ExampleTesting
In Simple Words:
Instead of testing a few hand-crafted example inputs (add(2, 3) == 5), Property-Based Testing tests universal mathematical invariants across thousands of randomized inputs:
typescript
import fc from 'fast-check';
test('reverse list property: reversing twice yields original list', () => {
fc.assert(
fc.property(fc.array(fc.integer()), (list) => {
expect(reverse(reverse(list))).toEqual(list);
})
);
});
- Automatically discovers edge cases human developers forget (e.g. negative numbers, empty arrays, unicode zero-width spaces, integer overflow) and "shrinks" failures to the minimal reproducible example.