博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
4.Spring 整合 Junit
阅读量:3888 次
发布时间:2019-05-23

本文共 1093 字,大约阅读时间需要 3 分钟。

文章目录

1.创建maven工程,导入jar包

org.springframework
spring-context
5.2.7.RELEASE
org.projectlombok
lombok
1.16.18
junit
junit
4.9
test
org.springframework
spring-test
3.2.4.RELEASE
provided

2.使用@RunWith 注解替换原有运行器

@RunWith(SpringJUnit4ClassRunner.class)public class SpringTest {}

3.使用@ContextConfiguration 指定 spring 配置文件的位置

@ContextConfiguration 注解:

locations 属性:用于指定配置文件的位置。如果是类路径下,需要用 classpath:表明

classes 属性:用于指定注解的类。当不使用 xml 配置时,需要用此属性指定注解类的位置。

@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations= {"classpath:bean.xml"})public class SpringTest {}

4.使用@Autowired 给测试类中的变量注入数据,进行测试

转载地址:http://gsphn.baihongyu.com/

你可能感兴趣的文章
【Architecture】CPU-bound(计算密集型) 和I/O bound(I/O密集型)
查看>>
【MacOS】Mac 系统下类似于 apt-get 的软件包管理器 -- Homebrew
查看>>
为窗口添加鼠标HOVER和LEAVE事件
查看>>
VC小技巧20个
查看>>
MFC Feature Pack for Visual C++ 2008的BUG之一
查看>>
POJ - 2739 Sum of Consecutive Prime Numbers
查看>>
STL map映照容器(一)map创建、元素插入、元素删除和遍历访问
查看>>
Leetcode - 557反转字符串中的单词III
查看>>
Leetcode - 160相交链表
查看>>
Leetcode - 11盛最多水的容器
查看>>
Leetcode - 141环形链表
查看>>
Leetcode - 14最长公共前缀
查看>>
Leetcode - 7整数反转
查看>>
PAT---B1022. D进制的A+B (20)
查看>>
PAT---B1037. 在霍格沃茨找零钱(20)
查看>>
PAT---A1019. General Palindromic Number (20)
查看>>
PAT---A1027. Colors in Mars (20)
查看>>
PAT---1058. A+B in Hogwarts (20)
查看>>
PAT---A1001. A+B Format (20)
查看>>
PAT---A1005. Spell It Right (20)
查看>>