Pcornel
Automation · Testing

Unit Testing

Cheat sheet · https://pcornel.dk/topic.php?topic=5926

Back to the Topic

Answer

Unit Testing isolates the smallest practical automation logic unit and verifies deterministic behavior against fast local inputs without requiring real external systems.

Remember

  • Unit pass ≠ integration works.
  • Mocked dependency response ≠ real dependency contract matches.
  • High unit coverage ≠ important system behavior covered.
  • Fast deterministic test ≠ production timing/race behavior exercised.

First checks

  • pytest -q — Python unit tests
  • Invoke-Pester -Path tests — PowerShell
  • bats tests/ — Bash

Commands

python -m pytest
Run the automation test suite in the active Python environment.
pytest -q <test-path>
Read-only/validation observation for pass/fail result and assertion/error output for the explicitly selected test scope.

Verify in this order

function + inputs → expected outputs

Where it usually breaks

Unit Testing proves local logic under controlled dependencies; it cannot prove external contracts, deployment wiring, permissions or end-to-end state changes.

Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.

Unit Testing testing proof-boundary map

BoundaryHealthy evidenceSuspicious evidence
Scope / oracleRequirement, case, expected result and exercised scope are explicitA generic green status exists without a trustworthy oracle or coverage boundary
Fixture / environmentData, dependencies and environment versions are reproducibleShared state, floating versions or stale fixtures make results non-reproducible
Effective outcomeAuthoritative state/read-back and service-relevant evidence match the expected resultTool/test/validator success substitutes for effective target or workload proof
Limits / next actionCoverage limits, unknowns and failures drive the next narrower checkUnknown evidence becomes pass, retries hide failures or broad success is inferred from one check

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5926

Confirmation

Confirm action

Continue?