-
for example: I've a function that should always return true, but somehow part of the falsely logic are being hidden in the function. The developer trust the generated test cases and don't realise the code change will break the function. Can property based testing able to address this kind of situation? function return_true(n) {
if (n > 999 && n < 100000) {
return false;
}
return true;
} test("should always return true", () => {
fc.assert(
fc.property(fc.integer(), (data) => {
const result = return_true(data);
expect(result).toBe(true);
})
);
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Actually it should find it. The buggy range being quite high (above 1000) it might take longer than if your range was 10 to 1000 but given enough runs (and you'll probably have enough via CI runs running everytime on your project), you'll find it. To find it even earlier you may tweak the numRuns options when running the test to run against 1m iterations for instance. |
Beta Was this translation helpful? Give feedback.
Actually it should find it. The buggy range being quite high (above 1000) it might take longer than if your range was 10 to 1000 but given enough runs (and you'll probably have enough via CI runs running everytime on your project), you'll find it.
To find it even earlier you may tweak the numRuns options when running the test to run against 1m iterations for instance.