Questions tagged «value-initialization»

7
如何在Spring中使用Mockito模拟自动装配的@Value字段?
我正在使用Spring 3.1.4.RELEASE和Mockito 1.9.5。在我的春季班上,我有: @Value("#{myProps['default.url']}") private String defaultUrl; @Value("#{myProps['default.password']}") private String defaultrPassword; // ... 从我目前设置的JUnit测试中可以看到: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "classpath:test-context.xml" }) public class MyTest { 我想为“ defaultUrl”字段模拟一个值。请注意,我不想模拟其他字段的值,我想保留它们的值,只保留“ defaultUrl”字段。另外请注意,setDefaultUrl我的班级中没有明确的“ setter”方法(例如),并且我不想仅为测试目的而创建任何方法。 鉴于此,我该如何模拟该字段的值?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.