阅读Spring 3.1中关于新的Cache Abstraction的内容,我想将此功能应用于我的项目.
我可以将调用缓存到没有参数的方法吗?
@Cacheable("xCache")
public List<X> loadAllX() {
...
}
Run Code Online (Sandbox Code Playgroud)
链接的博客文章指出
使用方法参数作为键来执行高速缓存查找
所以不应该缓存这种方法,对吗?
简短回答:是的,没有任何参数的方法将像任何其他方法一样被缓存.我猜这个方法的缓存中只有一个条目.
作为测试驱动开发的初学者,我刚刚遇到了一个问题.我的测试类开头如下:
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
@DirtiesContext
@ContextConfiguration(locations = {"/web-test.xml"})
public class XXTest {
@Autowired
XX xx;
@Autowired
HibernateTemplate template;
@Test
public void testSetGetXXValue() throws Exception {
final Map<String, YY> profilMap = new HashMap<String, YY>(2);
profilMap.put("1", new YY());
profilMap.put("2", new YY());
simpleCockpit.setValues(profilMap);
assertEquals(profilMap, simpleCockpit.getValues());
}
Run Code Online (Sandbox Code Playgroud)
如您所见,第一种测试方法改变了自动装配的XX级.这会影响以下所有测试方法,这些方法依赖于XX具有自动装配值.
如何从XX测试getter和setter并确保XX具有其他测试方法的自动装配值?
思考:
谢谢你的回答!我很确定这有一个简单的解决方案...... :)
编辑:关于是否单元测试getter/setter的问题,我决定这样做主要是因为http://www.sundog.net/sunblog/posts/should-we-test-getters-and-的状态.二传手.
我即将编写另一个涵盖新功能的Java测试.为了记录这个新测试的原因,我正在考虑通过对该功能的解释来评论测试.
我应该这样做吗?
将测试与功能联系起来的好方法是什么?