Environmentally Friendly Deployment

Keep your fan clean with environment tests

Deployment. After weeks of development the rubber finally hits the road... and often the shit hits the fan and the egg hits the face.

This time, the deployment of my project went smoothly thanks to a suite of Environment Tests, a technique I learned about at XTC and XP Day 4. An environment test verifies that the environment into which you are about to deploy an application is in the state that you expect: that expected directories exist; that files are readable when running under service accounts; that database logins are set up; that stored procedures have been loaded into the database; etc. etc. Environment tests are also used to verify that the development environment accurately reflects the production environment.

My first suite of environment tests were written in JScript and ran in the windows scripting host (WSH). JScript is easier to write than the Windows batch language but it's awkward to access the filesystem and other operating system functions from WSH.

But that wasn't the biggest problem. As I made my tests more accurate, the JScript tests ended up duplicating functionality in the application. For example, to test that my application would be able to connect to the database with its assigned username and password I had to parse the application's configuration file, generate the connection string and try a connection.

At this point I realised my mistake... I shouldn't have duplicated the functionality of the application in the tests, I should have used it. I therefore rewrote the tests in the same language as the application. The environment tests now call through the application code to probe the environment in exactly the same way as the actual application.

The application is structured as a package of core services - domain model, data mapping layer, etc. - that are used by multiple client packages. The clients include the deployed executables, some development tools for ad-hoc exploratory testing, the unit tests, the integration tests and now the environment tests.

Those environment tests have already saved my bacon more than once. At deploy time they detected that the application's login had not been set up correctly in the production database. Later, while helping with the install of another application, they detected that the install had deleted registry entries used by COM objects shared between the two applications. Both problems were easy to fix because they were detected by the environment tests without having to actually run the application in the live environment.

My fan is still shiny and clean and my face is still egg-free.

Update 27/05/2005: fixed link to Environment Tests presentation

Copyright © 2005 Nat Pryce. Posted 2005-05-25. Share it.

Comments powered by Disqus