How to test spring configuration classes?

In a word – “don’t”, that way lays madness.

What you really want is higher level tests that make use of your Spring configuration but are still focused on behaviour not implementation.

For example, looking at your security configuration – you don’t really care that the configure method is called, or what it does, what you want to test for is:

  1. Static pages don’t require authentication
  2. Other pages do require authentication
  3. Logging in works
  4. Logging out works

Using Spring for DI and security is merely how those things are implemented whereas your tests should be focused on the fact those things actually work.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)