lundi 23 mars 2015

Testing with spring configuration and Mocking objects

I am using a spring configuration in testing like below:



@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:config/spring/config.xml" })


Let's say I'm testing a service that depends on other services and a repository. Using the @ContextConfiguration these beans will be created and autowired into the service I am testing.


Is it considered better to mock these dependencies and repositories? When creating and loading a test configuration as done currently, a problem in a dependency could cause the test to fail, so I am not really only testing that one service but the other dependencies as well.


Should these dependencies be mocked in the unit test (since you are only supposed to test the functionality of that class and not its dependencies) but instantiated and wired in during integration tests?


Aucun commentaire:

Enregistrer un commentaire