Prefer Minimal, Fresh, Transient Fixtures

In xUnit Test Patterns, Meszaros [xTP] established a vocabulary for talking about tests. In particular, his terminology around fixtures clarifies and isolates a number of separable issues. This principle significantly leverages his terminology.

Fixtures establish the context for your test. They are the setup necessary to run your test. They construct, mock, dummy, inject, etc. the components necessary to run your test in as fast and isolated a way as possible.

Minimal fixtures are as large as necessary and no larger. Every fixture by necessity has elements that couple it to implementation. Although it is great to test by contract, you are testing real software with real implementation decisions. The more a fixture isolates the component under test, the more it behaves like other parts of the system. This couples it to those other parts, transitively coupling your test. In addition to making your tests faster and simpler, keeping your fixtures minimal reduces the coupling between your tests and the rest of the system.

Tests that use fresh fixtures recreate their fixtures for every test. The fresher the fixture, the less likely your tests will interact and the easier it will be to maintain each test in isolation from the others, reducing the coupling between tests.

Transient fixtures only exist for the duration of the test. They also act to reduce the potential interactions and coupling between tests.

The combination of minimal, fresh, and transient fixtures helps to reduce the coupling in your tests and to scale your testing effort in addition to providing the benefits of speed and isolation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.226.240