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