Tuesday, October 16, 2007

On using static fixtures

In my current project we are using fixtures to pre-configure domain objects for testing purposes. A discussion with my team lead has surfaced some interesting implications of misusing fixtures.

In our domain we have a concept of Application and we have an ApplicationFixture class that can createApplication() which returns an instance of applications pre-configured for some functional tests. The issue with this setup is that it makes it look like we can reuse this fixture not only in functional tests, but also in any other types of tests (eg. integration) which require an application. This may not be appropriate as the fixture could be introducing irrelevant dependencies/configuration to the integration tests.

In conclusion: Using fixtures is fine as long as they are used for the purpose they've been pre-configured for. Personally I like the idea of reflecting the purpose/test level of the fixture in its name.