The codebase is a typical spring corporate codebase with approximately 1.5 million lines of code. We have quite a few spring context files. The problem with testing is the problem.
In test cases, I created another set of test-spring files (basically it imports the corresponding contexts of the spring project), and for several beans it contains mocked beans for external services. All test classes use the same set of context configuration files, and everything is fine in 90% of cases.
But in some cases there will be a bean that I would like to make fun of. But I do not want to edit spring -text.xml (since this will bother all classes), and I do not want to have a separate xml set for each test class. It is very simple to say that doing this would be:
@Autowired @Qualifier("fundManager") FundManager fundManager; @Test public void testSomething(){ TransactionManager tx = mock(TransactionManager.class); fundManager.setTransactionManager(tx);
This works in some cases. But sometimes it is desirable that this new temporary bean tx should be installed where ever the TransactionManager bean has been used throughout the code base.
The IMHO proxy class is a great solution because I would have to wrap all the beans in a wrapper. This is what I am ideally looking for:
@Test public void testSomething(){ TransactionManager tx = mock(TransactionManager.class); replace("transactionManagerBean",tx);
BeanPostProcessor looks like an alternative suggestion, but I came across a few hiccups with it.
java spring unit-testing
Jatin
source share