Which describes a good unit test?
Options
- Slow but thorough, and depends on the internet
- Fast, isolated from others, and deterministic (Correct option)
- Tests many unrelated behaviors at the same time
- Only runs on the CI server and never locally
Answer
Fast, isolated from other tests and external systems, and deterministic (same result every run)
Why
Good unit tests run in milliseconds (so you run them constantly), don't depend on other tests or on the network/database (isolated), and always give the same result (deterministic).
Each test checks one behavior and has a name that explains it. If a test is slow or random, people stop trusting and running it.
Remember
Good unit test = fast, isolated, deterministic.