JUnit加载properties配置文件
来源:互联网 发布:linux c语言 sleep 编辑:程序博客网 时间:2024/05/16 13:45
项目测试通常需要在module的test包里用junit写测试样例,但是一般情况下我们会给各种环境使用不同的配置文件,那么在junit下是如何加载properties文件的呢?答案是通过注入类型为org.springframework.beans.factory.config.PropertyPlaceholderConfigurer的bean
1. 在test的resource下新建conf/spring-placeholder.xml文件
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans> <bean id="_test_config" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>classpath:conf/galax-dev.properties</value> </property> </bean></beans>
2. 新建junit的BaseTest.java, 在context中加载spring-placeholder.xml文件
@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = { "classpath*:/conf/spring-placeholder.xml",..........})public class BaseTest { }
0 0
- JUnit加载properties配置文件
- spring加载properties配置文件
- Properties--配置文件的加载
- properties加载配置文件demo
- python加载properties配置文件
- java加载.properties配置文件
- JAVA 动态加载properties配置文件
- spring加载外部properties配置文件
- Spring配置文件加载properties文件
- [Spring boot]配置文件properties加载
- 加载properties配置文件工具类
- spark加载properties配置文件方法
- 加载外部的properties配置文件
- Junit手动/自动加载spring配置文件
- Junit、Assert、内省、Properties类与配置文件的使用
- 单例模式加载properties配置文件
- Spring 配置数据源及properties配置文件加载
- JAVA Servlet 动态加载配置文件.properties
- Java方法参数传递方式总结
- HDU 5461 Largest Point(2015沈阳赛区网络赛+技巧水题)
- 策略模式(Strategy Pattern)
- PHP重定向三种方法详解
- 技术
- JUnit加载properties配置文件
- 字符串的最小表示法
- JVM 基础 VM运行机制
- Apache Awstats 安装配置系列 (4)之 Awstats 安装 配置
- linux下解压命令大全
- matlab第一周学习总结
- 微服务设计模式
- 白盒测试
- 2015全国大学生电子设计竞赛个人总结-F题