Quantcast
Viewing latest article 10
Browse Latest Browse All 14

Answer by toolkit for Spring beans redefinition in unit test environment

You can also write your unit tests to not require any lookups at all:

@ContextConfiguration(locations = { "classpath:/path/to/test-config.xml" })@RunWith(SpringJUnit4ClassRunner.class)public class MyBeanTest {    @Autowired    private MyBean myBean; // the component under test    @Test    public void testMyBean() {        ...    }}

This gives an easy way to mix and match real config files with test config files.

For example, when using hibernate, I might have my sessionFactory bean in one config file (to be used in both the tests and the main app), and have by dataSource bean in another config file (one might use a DriverManagerDataSource to an in-memory db, the other might use a JNDI-lookup).

But, definitely take heed of @cletus's warning ;-)


Viewing latest article 10
Browse Latest Browse All 14

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>