Skip to content

Insufficient test coverage: missing edge cases

Quick summary

Your tests only cover the typical case — edge cases, error paths, and boundary values are not tested.

Why this happens

  • Only the happy path was tested because edge cases were not considered

  • Error handling code paths have no tests because errors are hard to trigger

  • Boundary values like 0, -1, MAX_INT, and empty strings are not included in test data

Minimal example

✗ Broken code
test('divides numbers', () => {
  expect(divide(10, 2)).toBe(5); // only happy path — no edge cases
});
✓ Fixed code
test.each([
  [10, 2, 5],
  [0, 5, 0],
  [-10, 2, -5],
  [10, -2, -5],
])('divides %i by %i', (a, b, expected) => {
  expect(divide(a, b)).toBe(expected);
});
test('throws on divide by zero', () => {
  expect(() => divide(10, 0)).toThrow('Division by zero');
});

Using parameterized tests to cover edge cases and adding a test for the error condition ensures comprehensive coverage.

How to diagnose

  • Run a coverage tool and check for uncovered branches and error handling paths

  • Review the function for edge cases: empty input, null, boundary values, and error conditions

  • List all code paths and verify each has at least one test case

How to fix

  • Add test cases for edge cases: empty input, null, boundary values, and extreme values

  • Add tests for error conditions by mocking functions to throw or reject

  • Use parameterized tests to cover many input variations efficiently

How to prevent

  • Always consider edge cases when writing tests: empty, null, boundary, and error conditions

  • Use coverage tools in CI and fail the build if coverage drops below a threshold

Related Resources

Related Glossary

Related Lessons

← Back to language