Skip to the content ForoHackers
Log inJoin

Testing: start here

Testing
#3211 · · Quote · Report

Testing is running software on purpose to find out whether it does what it should. A test cannot prove there are no bugs, but a good suite catches regressions, documents behaviour and lets you change code without fear. The skill is choosing a few cases that are likely to expose a failure.

Key concepts

  • Levels: unit tests for small pieces, integration tests for parts together, end-to-end tests for whole flows.
  • Test design: boundary values, equivalence classes, error paths and the cases nobody thought of.
  • Isolation: test doubles such as stubs and mocks replace slow or unreliable dependencies.
  • Determinism: a test that fails randomly teaches people to ignore failures; remove time, order and network dependence.
  • Coverage and its limits: it shows what was run, not what was checked.

Vocabulary

  • Assertion: a statement in a test that must be true, or the test fails.
  • Regression: something that worked and stopped working.
  • Fixture: the prepared state or data a test starts from.
  • Property-based testing: checking general rules against many generated inputs.

What to study, in order

  1. Write unit tests for a small function with your language's standard test framework.
  2. Practise boundary values and error cases on a function that parses input.
  3. Replace a dependency with a fake, and test a piece that talks to a database or a clock.
  4. Write a property-based test and let it find a bug in your own code.
  5. Run tests on every change automatically, and track and fix flaky ones.

Related tags

#qa #ci-cd #debugging #fuzzing

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply