I have a problem with a (Spring) @Component that has a @PostConstruct method which access session data: in unit tests, *every* test that uses unitils is failing (before @Before even) because this particular bean doesn't find the session data it is looking for in its @PostConstruct method.
1) Why does unitils seem to be instantiating all Spring beans at once? Even tests that don't reference this bean are failing; if they use unitils, they fail now because of this bean.
2) If it has to be this way, how can I at least insert some test session data so that the bean can be instantiated ok?
I noted the test fails "before @Before even" because it means I can't even mock the data - the test fails before any code within it gets executed.
Thanks for any advice!
Rob
:)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Unitils only creates a classpath xml application context, the rest is done by Spring.
So if beans are loaded, i think it is caused by the configuration in the application context. For example component scanning will be done when the context is created.
The context will indeed be loaded before the @Before of your test. This allows you to use the context in the setup of your test.
In one of the next releases, the SpringModule will be made deprecated in favour of Spring's own base test classes.
Spring added some kind of unitils-like test-listener and we are going to make it possible that unitils plugs into this test listener. That way you can just use the base test classes of spring and still use all the unitils module behavior
best regards,
Tim
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi All,
I have a problem with a (Spring) @Component that has a @PostConstruct method which access session data: in unit tests, *every* test that uses unitils is failing (before @Before even) because this particular bean doesn't find the session data it is looking for in its @PostConstruct method.
1) Why does unitils seem to be instantiating all Spring beans at once? Even tests that don't reference this bean are failing; if they use unitils, they fail now because of this bean.
2) If it has to be this way, how can I at least insert some test session data so that the bean can be instantiated ok?
I noted the test fails "before @Before even" because it means I can't even mock the data - the test fails before any code within it gets executed.
Thanks for any advice!
Rob
:)
Hi Rob,
Unitils only creates a classpath xml application context, the rest is done by Spring.
So if beans are loaded, i think it is caused by the configuration in the application context. For example component scanning will be done when the context is created.
The context will indeed be loaded before the @Before of your test. This allows you to use the context in the setup of your test.
In one of the next releases, the SpringModule will be made deprecated in favour of Spring's own base test classes.
Spring added some kind of unitils-like test-listener and we are going to make it possible that unitils plugs into this test listener. That way you can just use the base test classes of spring and still use all the unitils module behavior
best regards,
Tim