F.I.R.S.T Principles
What Are the F.I.R.S.T Principles?
The FIRST principles were first proposed by Bob Martin, the author of the well-known book “Clean Code”. Unit tests are organized according to the F.I.R.S.T principles.
Fast
Unit tests should run quickly and produce results quickly.
Therefore, the unit of work should be as small as possible. To make tests fast, they should not use real servers or databases; instead, they should use fake data, or mock data.
Isolated / Independent
Unit tests should be executable on their own.
In other words, they must be independent and must not depend on or affect other tests.
Repeatable
Unit tests must be repeatable.
No matter where, how, or how many times a test is run, it should produce the same result.
Self-validating
Unit tests must be self-validating.
The test itself should produce a pass or fail result, and this should happen automatically.
Thorough / Timely
Unit tests must be thorough and written at the right time.
Being thorough means testing all data. Tests should include the range from minimum to maximum, cover data that changes by role, such as user and administrator cases, and also test which cases fail through exceptions or errors.