云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 通向架构师的道路(第二十五天)SSH的单元测试与dbunit的整合 - 图文

通向架构师的道路(第二十五天)SSH的单元测试与dbunit的整合 - 图文

  • 62 次阅读
  • 3 次下载
  • 2026/4/26 20:41:32

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. 28.

29. 30.

31.

32.

33. 34.

35. 36.

37. 38.

39. 40.

41. 42.

43. 44.

45. 46. 47.

48.

rceTransactionManager\> 49.

50. 51. 52.

53. 54.

55. 56.

57.

.Exception\ /> 58.

59.

ception\ /> 60.

61.

ception\ /> 62.

63.

ception\ /> 64.

65.

xception\ /> 66.

67. 68.

69. 70.

71. 72.

73. 74.

75. 76.

77. 78.

79. 80.

81.

tion\ />

82. 83. 84.

85. 86.

87.

.impl.*.*(..))\ /> 88.

89. 90. 91.

92.

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

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。 因为我们在做测试方法时势必会涉及到对一些数据进行操作,因此我们在数据

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com