I have a very large application with a very large application-context.xml file. I have many unit tests, and occasionally I want to write a quick unit test that replaces any particular bean with a mocked out replacement. I see that it's quite possible to create separate application-contexts for testing that can override small pieces of application-context, but is there a way to do this inline from a unit test class file?
In other words, if I have bean Foo, which has bean Baz as a property, which in turn has bean Bar as a property, and I want to replace Bar with mockBar for a single test, how could I do that?
I'd like it to look something like this:
Can this be done cleanly? How is something like this normally handled?
In other words, if I have bean Foo, which has bean Baz as a property, which in turn has bean Bar as a property, and I want to replace Bar with mockBar for a single test, how could I do that?
I'd like it to look something like this:
Code:
public void testSomething() { Bar mockBar = new Mock(Bar.class); context = createNewApplicationContextJustLikeOldOneExceptBarIs(mockBar); Foo foo = context.getBean("foo"); }
Comment