Reputation: 45692
I have: injecting MyClass
and String
objects into Utils
at constructor.
Questions:
Utils
constructor?MyClass
mock into Utils
object in unit tests? I mean how to redefine the bean definition?Utils.java
public class Utils {
@Inject
public Utils(MyClass obj, String val) {
this.obj = obj;
this.val = val;
}
Beans definition:
<bean class="com.mypack.MyClass"/>
<bean id="utils" class="com.mypack.Utils">
<constructor-arg value="bucket" />
</bean>
Upvotes: 0
Views: 111
Reputation: 22496
You can define define another(test) context for the unit tests:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "my-test-context.xml",
"some-other-context.xml" })
public class SkipSampleFunctionalTests {
@Autowired
private SomeBean bean;
...
}
If you want to override only one bean, you can import your main(core) context int the test context and change only the desired bean:
<import resource="main-context.xml"/>
<bean id="x" class="com.asd.MyClass">
<property name="y" ref="y"/>
</bean>
Upvotes: 1