idea下maven项目下spring junit 测试用例

使用idea在编写的类下右键Go->Test或者ctrl+shift+t,点击create new test会在相应目录下创建test类

别写代码如下

@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/config/**/applicationContext*.xml" }, loader = GenericXmlContextLoader.class)
@Transactional
public class BaseImageTextInfoActionTest extends AbstractCommonAction {
    @Autowired
    private BaseImageTextInfoService baseImageTextInfoService;

    @Test
    public void queryById() throws Exception {
      //具体代码
    }

}
@RunWith(value = SpringJUnit4ClassRunner.class)必须要写,相当于提供了spring的环境
@ContextConfiguration(locations = { "classpath:/config/**/applicationContext*.xml" }, loader = GenericXmlContextLoader.class)加载config下的所有目录下的以applicationContext的xml文件,加载相应的配置文件
@Transactional  测试方法会进入事务管理

pom文件,引入junit的jar包,最好是4.10版本以上的
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.10</version>
    <scope>test</scope>
</dependency>

2017-08-03 20:19:26

时间: 2024-08-07 16:21:59

idea下maven项目下spring junit 测试用例的相关文章

idea的maven项目下spring与mybatis整合

两周前学习mybatis框架,参考了网上多位大神的博客,但因为各种原因(不解释)总是没法成功搭建环境并运行项目.周末花了点时间阅读了文档并整理之前琐碎的内容,解决掉之前遇到的问题.现将整合环境的关键步骤整理成学习手记一篇. 文章只提取了整合环境的主体过程,没有太深入的解析其中内容,若想深入学习mybaits,请自行阅读文档.源码,或参看网上其他大神的博客,本人菜鸟一只,只是做做学习笔记(ps:吃货请直接拖到底部). 1.导入spring核心包.spring测试包.mybatis核心包.mysql

Maven项目下update maven后Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderL

Maven项目下update maven后Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderL     严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: org.springframework.web.co

Maven项目下 java.lang.ClassNotFoundException 常规解决办法

网上很多要修改.class .project的比较麻烦有时候还不一定管用.下面的方法适合于项目用已经引用了jar,但是运行时却ClassNotFound,请用如下方法试试: 严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: org.springframework.web

Maven项目下HttpServletRequest 或 HttpServletResponse需引用的依赖包

转载: http://xyly624.blog.51cto.com/842520/865630/ Maven项目下HttpServletRequest 或 HttpServletResponse需引用的依赖包:servlet-api.jar,并将scope设置为provided. pom.xml: <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifac

maven项目下solr和spring的整合配置

前言: solr和spring整合其实很简单,只要注意导入依赖的配置文件即可.废话不多说,上代码. 第一步:编写maven项目的pom文件,导入依赖 [html] view plain copy<project?xmlns="http://maven.apache.org/POM/4.0.0"?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"??????xsi:schemaLocation="

maven项目下tomcat直接启动不了(LifecycleException)。报错如下截图

经查,tomcat项目下的lib中没有jar包,发布的时候没有将jar包发布上去.这个问题在我的博客中以前遇到过.如何将maven的jar发布到项目中,我的博客里面有记载

读取Maven项目下resources目录下的配置文件(properties为例)

配置文件:xxxxx.properties 1 a.url=******************** 2 b.url=---------------------------------- 读取配置文件: public class ReadJdProperties { public String getUrlValue(String urlName) { String url = null; Properties prop = new Properties(); try { ClassLoader

Maven项目下 java.lang.ClassNotFoundException 常规解决的方法

网上非常多要改动.class .project的比較麻烦有时候还不一定管用.以下的方法适合于项目用已经引用了jar.可是执行时却ClassNotFound,请用例如以下方法试试: 严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: org.springframework.

Maven项目下update maven后Eclipse报错

java.lang.ClassNotFoundException: ContextLoaderL 严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener at org.