Isolating Tests
Learn about the importance of isolating tests from one another.
We'll cover the following
The meaning of test isolation
When we talk about test isolation, we are referring to the practice of creating boundaries between tests and test suites. We are isolating our tests and test suites from each other. Tests that are properly isolated from one another know nothing about the other's arguments, expectations, values, or mocks. Any changes to one test or test suite does not affect the outcome of any other test or test suite. Likewise, a test should perform in the exact same way regardless of location in a test file or whether tests before or after it are running. If test A only passes when it is run just after test B, we have a problem.
Why test isolation is important
At the core of test isolation is the importance of knowing exactly what is being tested. The ability to say, “given inputs of x, we expect an output of y, every single time” is fundamental to testing. These given variables not only have the actual arguments being passed into a function but also contain any sort of test state being configured by us, such as mocks, instances of a class, or configured values. Without effectively isolating one test from another, we have no way of knowing with confidence the totality of the givens.
Get hands-on with 1400+ tech skills courses.