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

图片网站 模板到什么网站做专利检索报告

图片网站 模板,到什么网站做专利检索报告,深圳网站运营,小游戏网站开发目录 一、配置文件方式 1.导入依赖 2.编写类和方法 3.配置文件applicationContext-test.xml 4.测试类 5.运行结果 二、全注解方式 1.编写类和方法 2.配置类 3.测试类 4.运行结果 每次进行单元测试的时候,都需要编写创建工厂,加载配置文件等相关…

目录

一、配置文件方式

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的核心依赖--><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.0.2.RELEASE</version></dependency><!-- https://mvnrepository.com/artifact/commons-logging/commons-logging --><dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.2</version></dependency><!-- https://mvnrepository.com/artifact/log4j/log4j --><!--日志--><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.12</version></dependency>------------------------------------------------------//主要是这个<!--测试--><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency>-------------------------------------------------------<!--连接池--><!-- https://mvnrepository.com/artifact/com.alibaba/druid --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.10</version></dependency><!--mysql--><!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.6</version></dependency>------------------------------------------------------------//也得有这个<!--spring-test--><!-- https://mvnrepository.com/artifact/org.springframework/spring-test --><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>5.0.2.RELEASE</version><scope>test</scope></dependency>----------------------------------------------------------</dependencies>

2.编写类和方法

把该类交给spring去管理

public class User {public void sayHello(){System.out.println("Hello--------------");}
}

3.配置文件applicationContext-test.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><!--整合单元测试--><bean id="user" class="com.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.yayakq.cn/news/583154/

相关文章:

  • 长宁区网站建设设计话色成品网站建设流程图
  • 做网站本溪wordpress丢失网络链接
  • 单位门户网站建设方案为网站网站做代理怎么判
  • 南通外贸网站建设做影视网站算侵权吗
  • 邹平县建设局官方网站门户网站是指
  • 新闻cms静态网站模板下载浙江设计公司
  • 南川网站建设公司wordpress个人电脑搭建
  • 网站建设方案模板下载网站开发云南
  • 建设银行 福建分行招聘网站wordpress旧编辑器
  • 太原建设北路小学网站长沙市天心建设局网站
  • 华为网站开发网站制作杭州
  • mvc5网站开发实战详解图片链接在线生成器
  • 注册网站需要多少腾讯云存储 wordpress
  • wordpress视频站模板国际新闻最快最及时的新闻软件
  • 快手作品推广网站广州商城型网站建设
  • 在线科技成都网站推广公司建站比较好的公司
  • 精通网站开发网站开发运营服务合同
  • 太原网站建设培训学校深圳分为哪几个区
  • 做的比较好的游戏网站国内的跨境电商平台有哪些
  • 产品目录网站模板二手商品网站的设计与建设论文
  • 网站建设基本完成网站广告布局
  • 网站开发好后要做什么济南网站设计报价
  • 美食网站开发计划国内精美网站
  • 用php做京东网站页面郓城菏泽网站建设
  • 物流信息网站阿里巴巴免费做网站吗
  • 广州网站建设高端网常州小程序开发公司
  • 网站建设 淘宝描述psd做网站的为什么不给域名和密码
  • 网站要不要备案做python项目的网站
  • 网站准确的定位土豆网网站开发源代码
  • 做引流去那些网站好wordpress 微信同步