Hosted by:
Unit testing expertise at your fingertips!
Home | Discuss | Lists

Make Resource Unique

The book has now been published and the content of this chapter has likely changed substanstially.

Several tests are accidentally creating or using the same resource in a Shared Fixture.

Make the name of any resources used by a test unique.

From [RTC].

A lot of problems originate from the use of overlapping resource names, either between different tests run by the same user or between simultaneous test runs done by different users.

Such problems can easily be prevented (or repaired) by using unique identifiers for all resources that are allocated, for example by including a time-stamp. When you also include the name of the test responsible for allocating the resource in this identifier, you will have less problems finding tests that do not properly release their resources.

Implementation Notes

We make the name of any resources used by a test unique across all tests by using a Distinct Generated Value (see Generated Value on page X) as part of the name. Ideally, the name should include the name of the test that "owns" the resource. To avoid self-Interacting Tests (see Erratic Test on page X), include a time-stamp in the name of any resources the tests create and use Automated Teardown (page X) to delete the resources at the end of the test.

Page generated at Wed Feb 09 16:39:52 +1100 2011

Copyright © 2003-2008 Gerard Meszaros all rights reserved

All Categories
Introductory Narratives
Web Site Instructions
Code Refactorings
Database Patterns
DfT Patterns
External Patterns
Fixture Setup Patterns
Fixture Teardown Patterns
Front Matter
Result Verification Patterns
Test Double Patterns
Test Organization
Test Refactorings
Test Smells
Test Strategy
Value Patterns
XUnit Basics
xUnit Members
All "Test Refactorings"
Extract Testable Component
Inline Resource
Make Resource Unique
Minimize Data
Replace Dependency with Test Double
Setup External Resource