Skip to main content
InterviewHubPRO
Section Overview
Q11

Question 11 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

22%
Software Testing & QA (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

Property-Based Testing vs. Example-Based Testing (fast-check / hypothesis).

senior LevelCode ExampleTesting

In Simple Words:

  • Example-Based Testing: You hardcode specific inputs and test known outputs: add(2, 3) === 5. Misses edge cases like negative zeros, integer overflows, or malformed unicode strings.
  • Property-Based Testing (fast-check):
    • You define mathematical invariants or universal properties that must hold true for all valid inputs:
      typescript
      import fc from 'fast-check';
      
      // Property: Reversing an array twice produces the original array
      fc.assert(
        fc.property(fc.array(fc.integer()), (arr) => {
          expect(reverse(reverse(arr))).toEqual(arr);
        })
      );
      
    • The framework generates thousands of randomized, fuzzing inputs. When a failure is found, it automatically shrinks the input to the smallest reproducible edge case (e.g., "" or 0).