Skip to main content

Posts

Showing posts from December, 2010

Speeding up Spring integration tests

The biggest problem with unit testing using Spring testing support* is the time it takes to initialize the Spring framework context. Every new test case adds precious seconds to overall build time. After a while it will take minutes or even hours to fully build the application, while most of this time is consumed by Spring itself. But we'll start from the basics.
In order to make JUnit aware of Spring framework test support, simply add these annotations on test case class:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @Transactional public class MainControllerTest { //... }
While @Transactional is not necessary, it will greatly simplify testing when database is involved (details here). In IntelliJ IDEA 10 (I just took this brand new version for a test drive) these annotations will raise the following error to occur:


And suggested solution: