foundation17 min studyLesson 8 in Engineering

Tests as evidence, reproducibility as a method

Build checks around behavior and invariants, then record enough context to reproduce a result.

On this page

What you’ll understand

  • Distinguish unit, integration, and end-to-end evidence.
  • Design tests that challenge requirements rather than repeat implementation.
  • Explain why a random seed alone does not guarantee reproducibility.

A passing test is evidence about a particular behavior under particular conditions. It is not a certificate that the entire system is correct. Useful testing starts with a requirement, chooses observations that could reveal a violation, and records enough context for someone else to investigate. The same discipline supports trustworthy AI experiments and repeatable infrastructure changes.

Choose the smallest meaningful boundary

A unit test can check a pure transformation without starting a database. An integration test can check whether a real database enforces a uniqueness rule. An end-to-end test can verify that a user submits a valid request and sees the resulting state. These names describe boundaries, not a ranking of virtue. Choose the boundary at which the requirement can actually fail, balancing speed, realism, and diagnostic clarity.

A test that computes its expected answer with the same logic as the implementation can preserve the same mistake twice. Derive examples independently, use known results, and include boundary cases. For a normalization function, test empty input policy, invalid values, and a property such as a valid output sum. For an API, check both accepted requests and the documented behavior for malformed or repeated submissions.

∣y^−y∣≤a+r∣y∣|\widehat{y}-y|\leq a+r|y|
This is one explicit approximate-comparison rule, with absolute tolerance a in output units and relative tolerance r dimensionless. y is the reference. Choose tolerances from the requirement rather than copying arbitrary constants.↔ Scroll wide equations horizontally.

Reproducibility needs a complete context

A reproducible computation needs recorded inputs, code, dependencies, configuration, and relevant execution conditions. Setting a seed controls a particular pseudorandom sequence, but parallel scheduling, nondeterministic operations, library versions, and hardware can still change results. Separate exact replay from statistical reproducibility: repeated training may produce different parameters while still supporting the same conclusion within a measured range of variation.

Keep test data small enough to understand and representative enough to reveal the behavior being checked. Do not put private production records or secrets into fixtures. For an experiment, record data splits and preprocessing as carefully as model code; otherwise a result can change without an obvious source edit. When a test fails, preserve the minimal relevant evidence and identify whether the failure concerns code, data, environment, or the test's own assumptions.

p^=kn\widehat{p}=\frac{k}{n}
k observed failures in n trials produce an empirical failure fraction, which is dimensionless. This statistic alone is not a guarantee of the true rate, and correlated or unrepresentative trials weaken its interpretation.↔ Scroll wide equations horizontally.

Treat uncertainty and flaky tests honestly

An intermittent failure can expose a race, an external dependency, or a timing assumption in the test. Rerunning until green hides evidence if the underlying cause remains. Isolate dependencies where appropriate, use explicit readiness conditions instead of arbitrary delays, and retain failing traces. If the product requirement involves a real integration, preserve a meaningful integration check rather than replacing every dependency with a convenient mock.

The lab shows an exact binomial distribution for a chosen success probability and independent trial count. It does not run tests or infer the probability from data. Label an event consistently as success, vary the assumed probability, and observe how the predicted count distribution changes. Correlated test cases or shared blind spots violate the independence model, so do not interpret its bars as proof of coverage. Before adding more tests, ask which unverified requirement the new test would challenge and what a failure would teach you.

Validate a precision change

A preprocessing change produces values near a reference of 100 units. The agreed rule uses an absolute tolerance of 0.01 units and relative tolerance of 0.001.

  1. Compute the allowed difference from the documented rule: 0.01 + 0.001 × 100 = 0.11 units. Keeping units visible prevents confusing a fraction with a percentage or a raw value.

  2. An output of 100.08 differs by 0.08 and passes this numerical check. An output of 100.2 differs by 0.2 and fails. Derive these expected outcomes independently of the implementation.

  3. Repeat on near-zero, negative, large, and invalid inputs as the contract requires. Passing these examples still does not prove downstream task quality; include an appropriate separate behavioral evaluation for that requirement.

The result

The tolerance test supplies clear evidence for a stated numerical contract. It cannot silently stand in for every quality or compatibility requirement.

Explore the model

Interactive lab

Interactive lab · probability

A stated probability predicts a distribution

Choose success probability p and trial count n to inspect exact binomial bars, mean np, and variance np(1−p). Trials are independent with constant p by assumption; the lab neither runs software tests nor estimates p from evidence.

A stated probability predicts a distributionThese are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Current readings: Mean · np: 5; Variance · np(1−p): 2.5; Total probability: 1. All parameters are adjustable with the labeled controls below.03581000.070.150.220.3Successes kP(X = k)k = 0 · P = 9.77e-4
Exact probabilityHighlighted outcomeMean np
Mean · np
5
Variance · np(1−p)
2.5
Total probability
1
t = 0 s

These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA probability model predicts outcomes only under its assumptions; correlated tests can share the same blind spot.

Check your understanding

Why might a fixed random seed fail to reproduce a training result exactly?

Try it yourself

A simulation fails three times in 1,000 trials. What empirical fraction did you observe, and why does it not establish a production guarantee?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Divide failures by trials, then inspect how the trials were chosen.

Compare with the solution

The empirical fraction is 0.003, or 0.3%. The sample may be small, correlated, or unlike production traffic, and rare cases may be missing. Report the observation with its conditions; a guarantee would require a justified model and stronger evidence than this single fraction.

Take it with you

  • Test requirements at boundaries where they can actually fail.
  • Reproducibility needs inputs, code, configuration, and environment.
  • A passing sample or a fixed seed is evidence with limits.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.