Optimizing test setup and cleanup for performance

There is an interesting post from Andrejs Doronins on LinkedIn about improving test performance:

https://www.linkedin.com/posts/andrejs-doronins-195125149_testautomation-activity-6889222015509639169-duEW

I replied and added my own comments below:

Remember though, that execution time is trivial compared to development, maintenance, and debugging.

So if you’re adding what seems like extra effort that slows down execution to have a clean environment and setup each time — the savings on reliable tests that pass consistently and find errors that tests that don’t “start from scratch” won’t find is so much greater.

That said — you can be smart in your initialization.

Things like initializing your database with common data only once before a test run, instead of on every test case. Or modifying environment configuration only for a specific suite that needs it can save valuable time compared to doing it for each test.

But this optimizations are sometimes not apparent when you write the tests — or may only apply to 1 test at first, and only become generalized as your test coverage grows.

The trouble here is, that rarely do you have time to go back and review working tests or a test framework to consider how you could optimize.

In this regard, once again, test code imitates production code.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s