Home » Articles, Knowledge

Improving Java Unit Tests Speed

10 October 2012 No Comment

This article by Lasse Koskela, provides several tips on how to improve the speed of your Java unit tests. The strategy to improve the speed up test code is to find slow things and either make them run faster or not run them at all.

The tips provided in the article are:
* Don’t let your test set up things you will never use: base classes typically host a number of utility methods as well as common setup and teardown behaviors. This code may be an additional convenience for you as a developer who writes tests, but there is also a potential cost.
* Limit the code executed in your test: the more code you execute, the longer you unit tests will take to finish. Sometimes, it is however not so much about the number of instructions you execute but the type of instruction.
* Stay local, stay fast: keep your tests as local as possible, devoid of any slow network calls.
* Minimize access to the database: it is slow and the actual property of your objects is likely irrelevant to the logic and behavior your unit test. Correct persistence is something you want to check during integration tests.
* Minimize access to the file system and disable logging

Related Content:

Comments:

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.

*