当前位置:首页 > 通向架构师的道路(第二十五天)SSH的单元测试与dbunit的整合 - 图文
7. 8. 9.
import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringJUnit4ClassRunner.class)
10. @ContextConfiguration({ \
/ds/datasource.xml\
11. \12. public class BaseSpringContextCommon { 13. }
该类为一个基类,我们所有的单元测试类全部需要继承自该类,大家可以把这个类认为一个spring的context加载器,注意这边的datasource.xml。
因为我们在做测试方法时势必会涉及到对一些数据进行操作,因此我们在数据库里除了平时开发和布署用的数据库外,还有一个专门用于运行“单元测试”的“单元测试数据库”或者“单元测试数据库实例”,因此我们在单元测试时会把我们当前的数据库连接“硬”指向到“单元测试用数据库”上去.
这个datasource.xml文件位于/org/sky/ssh/ut/ds目录下,见下图(当然它也必须被放在test/main/java目录里哦:
该文件内容如下:
org.sky.ssh.ut.ds.datasource.xml [html]view plaincopyprint?
1. 2.
3. xmlns:aop=\ xmlns:tx=\ramework.org/schema/tx\ 4. xmlns:context=\ xmlns=\springframework.org/schema/beans\ 5. 6. xsi:schemaLocation=\ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 7. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 8. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 9. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd\> 10. 11. 12. 13. 14. ource\ /> 15. 16. 17. 25. 26. 27. 29. 31. 32. 33. 35. 37. 39. 41. 43. 45. 48. rceTransactionManager\> 49. 50. 53. 55. 57. .Exception\ /> 58. 59. ception\ /> 60. 61. ception\ /> 62. 63. ception\ /> 64. 65. xception\ /> 66. 67. 69. 71. 73. 75. 77. 79. 81. tion\ /> 82. 83. 84. 85. 87. .impl.*.*(..))\ /> 88. 89. 92.
共分享92篇相关文档