当前位置: 首页 > news >正文

永久网站空间医院 网站建设 新闻

永久网站空间,医院 网站建设 新闻,chinacd.wordpress变身,长安外贸网站建设一、前言 提供服务的时候#xff0c;为了保证服务的正确性#xff0c;有时候需要编写测试类验证其正确性和可用性。以前的做法都是自己简单写一个控制层#xff0c;然后在控制层里调用服务并测试#xff0c;这样做虽然能够达到测试的目的#xff0c;但是太不专业了。还是老… 一、前言   提供服务的时候为了保证服务的正确性有时候需要编写测试类验证其正确性和可用性。以前的做法都是自己简单写一个控制层然后在控制层里调用服务并测试这样做虽然能够达到测试的目的但是太不专业了。还是老老实实的编写测试类进行测试吧。 二、Junit4依赖 dependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.12/version /dependency dependencygroupIdorg.springframework/groupIdartifactIdspring-test/artifactIdversion4.2.5.RELEASE/versionscopetest/scope /dependency   如果出现如下异常      则加入如下依赖。 dependencygroupIdjavax.servlet/groupIdartifactIdservlet-api/artifactIdversion3.0.1/versionscopetest/scope /dependency 三、目录结构      四、测试类   通过自动注入方式获取bean import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.alibaba.fastjson.JSONObject; import com.yyjz.icop.usercenter.service.ISupplierService; import com.yyjz.icop.usercenter.vo.SupplierVO;RunWith(SpringJUnit4ClassRunner.class) ContextConfiguration(locations{file:src/main/webapp/WEB-INF/config/applicationContext.xml,file:src/main/webapp/WEB-INF/config/applicationContext-jpa.xml, }) // 加载配置 public class UserExtTest{Autowiredprivate ISupplierService supplierService;Testpublic void addSupplier(){SupplierVO vo new SupplierVO();vo.setSupplierId(1234567890);vo.setUserName(hjzgg);vo.setUserCode(hjzgg);vo.setUserMobile(1567c637914);JSONObject ans supplierService.addSupplier(vo);System.out.println(ans.toJSONString());} }    注ContextConfiguration中locations文件配置如果文件放在了WEB-INF/config目录下配置如上所示。如果配置文件放入src/main/resources目录下则改成calsspath:applicationContext.xml和calsspath:applicationContext-jpa.xml 。   同时如果配置文件中引用了properties的文件也要改一下路径。测试完成之后在改回去。        通过上下文获取bean import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration;import com.alibaba.fastjson.JSONObject; import com.yyjz.icop.usercenter.service.ISupplierService; import com.yyjz.icop.usercenter.service.impl.SupplierServiceImpl; import com.yyjz.icop.usercenter.vo.SupplierVO;RunWith(SpringJUnit4ClassRunner.class) ContextConfiguration(locations{file:src/main/webapp/WEB-INF/config/applicationContext.xml,file:src/main/webapp/WEB-INF/config/applicationContext-jpa.xml, }) // 加载配置 WebAppConfiguration public class UserExtTest{Autowiredprivate ApplicationContext ac;Testpublic void addSupplier(){ISupplierService supplierService ac.getBean(SupplierServiceImpl.class);SupplierVO vo new SupplierVO();vo.setSupplierId(1234567890);vo.setUserName(hjzgg);vo.setUserCode(hjzgg);vo.setUserMobile(15670637914);JSONObject ans supplierService.addSupplier(vo);System.out.println(ans.toJSONString());} }   WebAppConfiguration测试环境使用用来表示测试环境使用的ApplicationContext将是WebApplicationContext类型的value指定web应用的根。默认值是String value() default src/main/webapp; 五、总结   至此测试类的简单使用完成。还需要更进一步学习测试类。 转载于:https://www.cnblogs.com/hujunzheng/p/5840479.html
http://www.sadfv.cn/news/145323/

相关文章:

  • 网站开发需要注册账户吗智联招聘网站多少钱做的
  • 笔记本电脑做网站比较畅快做网站要开发嘛
  • 网站首页模板设计图深圳小程序搭建
  • 邯郸建立网站费用ps制作网站导航图片
  • 小猫济南网站建设公司合肥关键词排名首页
  • 网站制作代码大全上海网站建设价钱
  • 电商网站的建设的主要目的龙岗平湖网站建设公司
  • 网站开发使用软件有哪些永川网站制作
  • 用6数字域名做网站的是网业翻译成中文
  • 网站前期设计企业信息查询单在哪里打印
  • 聊城集团网站建设流程徐州市徐州市城乡建设局网站首页
  • 个人网站制作教程wordpress 登录评论
  • 福州专业网站建设价格手机app软件开发公司排名
  • CQ网络科技网站建设广东近期新闻
  • 中通服建设有限公司网站料远若近网站建设
  • 找印度人做网站松阳建设局网站
  • dede电影网站模版wordpress 火车采集
  • 优化网站定制网站关键字代码
  • 阳泉住房和城乡建设厅网站公司logo设计价格
  • 网站收录怎么提高提供佛山网站制作
  • 怎么建网站不用买空间学校网站建设经验介绍
  • 仁怀网站建设江苏财经职业技术学院会计系示范校建设专题网站
  • 人才网站建设cms大型网站频道的建设需多人协同开发
  • 国外游戏商城网站欣赏自己如何做链接推广
  • 抚州制作网站哪家公司好葫芦岛住房和城乡建设厅网站
  • iis6.0不能新建网站智慧团建官方网站登录入口
  • 手机网站建站软件做网站服务好
  • 如何用群晖做自己的网站怎么弄自己的网址
  • 建设好网站外链有哪些方式公司在线网站制作系统
  • 移动商城网站开发抖音代运营价格