JavaScud | Forum | JIRA | Blog |
  Dashboard > SpringSide > Home > UnitTestGuide
  SpringSide Log In View a printable version of the current page.  
  UnitTestGuide
Added by calvin, last edited by calvin on Aug 31, 2006  (view change)
Labels: 
(None)

1. 需要Spring 依赖注入的测试

AbstractDependencyInjectionSpringContextTests,实现public String[] getConfigLocations()函数, 返回applicationContext文件路径的数组,并显式写一些需要注入的变量的setter函数。

注意Spring 默认是autowire by type的,所以可能需要在getConfigLocations()函数里,setAutowireMode(AUTOWIRE_BY_NAME);把它设回by name。

2. Dao测试

AbstractTransactionalDataSourceSpringContextTests 在测试后会默认回滚所有的操作。如果需要在测试后提交,需要setRollBack(false);

还通过注入的DataSource创建了一个JDBCTemplate 对象,可以跑SQL帮忙核对Hibernate的结果,但要注意两者的事务。

3. Controller测试

Controller测试一般要用MockObject 分离Service层,要copy WEB-INF/下的相关文件copy 到classpath,而且Controller不含太多的逻辑,所有测试controller有点吃力不讨好,建议直接用seleuim进行集成测试

Site running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators