maven配置JUnit环境
2017-10-09 19:28
246 查看
pom.xml
基础类BaseTest.java
测试类
项目结构目录参考之前一篇:http://blog.csdn.net/h996666/article/details/78124232
遗留问题:不知道为什么测试时创建数据库链接很慢,要卡很长时间。
--------------------------------------2017/10/18补充------------------------------------------------------------
测试时,创建数据库链接慢。还没搞清楚,我现在换了数据库的连接池,使用阿里的druid,
测试时,发现创建数据库链接快很多,并没有出现长时间等待现象。
<!-- JUNIT测试架包 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-juli</artifactId> <version>7.0.21</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${srping.version}</version> <scope>test</scope> </dependency>注意tomcat-juli必要引入,否则会报错,错误信息:java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory
基础类BaseTest.java
import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * 测试基类 * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:/spring/applicationContext-service.xml", "classpath:/spring/applicationContext-dao.xml", "classpath:/spring/applicationContext-redis.xml"}) public class BaseTest { // // extends AbstractTransactionalJUnit4SpringContextTests 需要回滚时继承 }
测试类
import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import com.service.redis.RedisService; import test.service.BaseTest; public class RedisServiceTest extends BaseTest { @Autowired private RedisService redisService; @Test public void testGet() { System.out.println(redisService.get("address")); } @Test public void test() { System.out.println("xxx"); } }
项目结构目录参考之前一篇:http://blog.csdn.net/h996666/article/details/78124232
遗留问题:不知道为什么测试时创建数据库链接很慢,要卡很长时间。
--------------------------------------2017/10/18补充------------------------------------------------------------
测试时,创建数据库链接慢。还没搞清楚,我现在换了数据库的连接池,使用阿里的druid,
测试时,发现创建数据库链接快很多,并没有出现长时间等待现象。
相关文章推荐
- maven环境配置
- Maven的pom.xml文件结构之环境配置distributionManagement
- ubuntu maven环境安装配置以及工程创建
- win10安装配置maven环境
- Using Maven profiles and resource filtering(针对不同环境启用不同的配置值)
- eclipse基础环境配置和svn、maven的配置以及maven的安装
- Maven – 环境配置
- maven 环境变量设置和Java maven工具配置 on windows 7
- Jenkins+maven+SVN+Tomcat持续集成发布环境安装和配置
- IDEA-Maven环境配置及使用教程
- Maven学习笔记(一)—— 下载、安装Maven并配置Maven的环境变量
- Springmvc maven环境配置
- Maven 多环境配置:开发,测试,生产环境
- Mac环境下配置Java开发环境(jdk+maven+tomcat+idea)
- Maven3.0.3的环境变量配置
- Maven环境配置
- maven配置环境
- 配置junit+TOMCAT配置和环境变量
- Maven学习笔记(一)-Maven安装与环境变量配置
- Maven配置本地环境和线上环境