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

图片网站 模板杭州建设网造价平台

图片网站 模板,杭州建设网造价平台,西安seo主管,企业建设网站的过程和预算表目录 一、配置文件方式 1.导入依赖 2.编写类和方法 3.配置文件applicationContext-test.xml 4.测试类 5.运行结果 二、全注解方式 1.编写类和方法 2.配置类 3.测试类 4.运行结果 每次进行单元测试的时候#xff0c;都需要编写创建工厂#xff0c;加载配置文件等相关…目录 一、配置文件方式 1.导入依赖 2.编写类和方法 3.配置文件applicationContext-test.xml 4.测试类 5.运行结果 二、全注解方式 1.编写类和方法 2.配置类 3.测试类 4.运行结果 每次进行单元测试的时候都需要编写创建工厂加载配置文件等相关操作比较繁琐现在Spring提供了整合Junit单元测试的技术可以简化测试开发所以必须首先要有Junit单元测试的环境也就是要导入Junit单元测试的依赖还有spring-test的依赖 这里用了两种方式去整合一种是配置文件的方式一种是全注解的方式 一、配置文件方式 1.导入依赖 需要导入spring的核心依赖、Junit单元测试的依赖和spring-test的依赖 dependencies!--spring的核心依赖--dependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion5.0.2.RELEASE/version/dependency!-- https://mvnrepository.com/artifact/commons-logging/commons-logging --dependencygroupIdcommons-logging/groupIdartifactIdcommons-logging/artifactIdversion1.2/version/dependency!-- https://mvnrepository.com/artifact/log4j/log4j --!--日志--dependencygroupIdlog4j/groupIdartifactIdlog4j/artifactIdversion1.2.12/version/dependency------------------------------------------------------//主要是这个!--测试--dependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.12/versionscopetest/scope/dependency-------------------------------------------------------!--连接池--!-- https://mvnrepository.com/artifact/com.alibaba/druid --dependencygroupIdcom.alibaba/groupIdartifactIddruid/artifactIdversion1.1.10/version/dependency!--mysql--!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --dependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdversion5.1.6/version/dependency------------------------------------------------------------//也得有这个!--spring-test--!-- https://mvnrepository.com/artifact/org.springframework/spring-test --dependencygroupIdorg.springframework/groupIdartifactIdspring-test/artifactIdversion5.0.2.RELEASE/versionscopetest/scope/dependency----------------------------------------------------------/dependencies 2.编写类和方法 把该类交给spring去管理 public class User {public void sayHello(){System.out.println(Hello--------------);} } 3.配置文件applicationContext-test.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd!--整合单元测试--bean iduser classcom.test.pojo.User/bean /beans 4.测试类 import com.test.pojo.User; 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;/* * Spring整合Junit单元测试 * */ RunWith(value SpringJUnit4ClassRunner.class) //运行单元测试 ContextConfiguration(value classpath:applicationContext-test.xml)//加载类路径下的配置文件 public class Demo {//按类型自动注入Autowiredprivate User user;Testpublic void run1(){user.sayHello();} } 5.运行结果 二、全注解方式 依赖没有变只是没有配置文件了换成了配置类 并且重新换了一个类Customer没有用配置文件方式里的User类 1.编写类和方法 import org.springframework.stereotype.Component;Component public class Customer {public void save(){System.out.println(保存客户);} } 2.配置类 import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration;Configuration//声明当前是配置类 ComponentScan(value com.test.pojo) //扫描包 public class SpringConfig {} 3.测试类 import com.test.config.SpringConfig; import com.test.pojo.Customer; 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;RunWith(value SpringJUnit4ClassRunner.class) //运行单元测试 ContextConfiguration(classes SpringConfig.class)//加载配置类 public class Demo1 {Autowired //按类型注入private Customer customer;Testpublic void run1(){customer.save();}} 4.运行结果
http://www.hkea.cn/news/14282682/

相关文章:

  • 做百度推广去些网站加客户网站建设的费用估算
  • 网站风格设计描述wordpress 邮件通知 密码
  • 本地唐山网站建设建设网络文化网站的请示
  • 怎么找网站做公示都有哪些网站
  • 宣传型网站赶集网网站建设费用
  • 局域网手机网站建设app宣传推广方案
  • 河北建设工程信息网正规网站郑州市域名服务公司
  • 手机网站建设免费wordpress 固定网址
  • 福州建设工程质量监督网站wordpress登陆死循环
  • wordpress交易网站吗企业策划公关公司
  • 填表网站怎么做浙江省2011年1月高等教育自学考试 网站建设与管理试题与答案
  • 搜狐快站怎么样wordpress建站行吗
  • 做的网站上更改内容改怎么办关于网站设计的价格
  • 百度网站收录更新网站开发实用技术介绍
  • 杭州高端网站设计产品设计招聘网站
  • 网站icp不备案有关系吗咖啡网站建设
  • wordpress全站301各大设计网站
  • 搭建网站要什么配置网站优化包括
  • 个人网站 创意泉州网站建设报价
  • 微软的网站开发软件北京中小型网站建设
  • 网站建设捌金手指下拉二八桓台建设局网站
  • 博星卓越电子商务网站建设实训平台鱼骨建站公司
  • 东莞网站页设计制作wordpress 文章字段
  • 东莞网站建设商城网站公司 百度百科
  • 重庆网站建设论坛中国外发加工网app
  • 城乡建设局的官方网站哪些公司做网站开发
  • 彩妆网站建设什么是网站框架结构
  • 婚庆公司简介seo网站建站
  • 残疾人信息无障碍网站建设手机建模软件
  • 怎样开发手机网站建设深圳网页设计网页制作