Skip to content

jonocode – a developer's blog

I moved! –>

These are Robert C. Martin’s five rules for writing clean test code.  They form the acronym F.I.R.S.T.

Your tests should be fast so that you will run them frequently.  If they run slowly, you won’t want to run them as often.  If some tests must be slow, try to partition them out so you can run the fast tests more often.

Each test should run independently.  An error in one test should not cause tests after it to fail.

They should run anywhere, anytime.  Variables external to the system should not affect their outcome.

There are only two possible outcomes.  The test passed, or the test failed.  No in-between.  Judging whether or not a test passed should not be a matter of opinion.

Unit tests should be written just before the production code that makes them pass.  This helps you write code that is testable.

Robert C. Martin, Clean Code — A Handbook of Agile Software Craftmanship


%d bloggers like this: