Skip to content

jonocode – a developer's blog

I moved! –> http://pressreload.com

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

Fast
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.

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

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

Self-validating
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.

Timely
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

Advertisements

%d bloggers like this: