Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Best Practices

Be Test-Driven

Brendan Hofmann - I'm not sure I agree with this one. A lot of development is iterative in nature, and TDD can make that more expensive. We should have best-practices beyond TDD as well.

Follow the Test-Driven Development Test Cycle.

...

Never assert or verify the same behavior in more than one test.

Brendan Hofmann This should be reworded so it doesn't unintentionally exclude interacting permutations of otherwise identical behaviors.

Mock Dependencies

When writing unit or component tests, mock all dependencies that may fail. This allows the tests to guarantee that the unit or component under test behaves as excepted when one of its dependencies fails.

...

This usually indicates that some tests are not properly cleaning up after themselves or are not properly setting up their test prerequisites.

Anti-Patterns

Sleeps

Brendan Hofmann I could see an argument that everything in this category should be in component tests instead of unit tests.

Sleeps in tests should be avoided as they open the door to timing issues and race conditions, slow tests down and are a major cause of test flakiness.

...

Repeated Given, When or Then sections in a BDD test, or difficult to name tests are usually two good indicators that a test is doing too much.

Brendan Hofmann What is the right way to unit test sequential behaviors then? We should provide positive guidance to follow instead.