mardi 29 septembre 2015

Inheriting java config classes in unit tests in Spring

I'm writing unit tests for pure java-config styled application with pretty big amount of configuration classes. To test some high-level logic I have to import a pack of configs. So, finally, the context declaration looks kinda:

@ContextConfiguration(
    classes = {
            // Common application configurations
            BaseBusinessConfiguration.class, BusinessServicesConfiguration.class, 
            nts.trueip.gatekeeper.logic.configuration.ContextConfiguration.class,
            ControllersConfiguration.class, FactoriesConfiguration.class, CachingConfiguration.class,
            InterpretersConfiguration.class, UtilConfiguration.class, ValidatorsConfiguration.class,
            // Common test environment configurations
            MockedReposConfiguration.class, TestServicesConfiguration.class,
            // Local test configuration
            LogicTestConfiguration.class 
    }
    )

I have to specify them for every test class in the project, and the majority of them are the same all the time, only some specific configurations may vary. According to the @ContextConfiguration specification, it's possible to inherit locations and initializers from test superclass, but not classes.

Is there any practise to avoid so bulk configurations, moving some parts in superclasses/some side classes?

Aucun commentaire:

Enregistrer un commentaire