zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    (五)Ajax修改购物车单品数量
    (四)加入购物车和购物车操作
    flask blueprint
    2.1.2 BCD码
    2.1.1进位计数制
    1.2.3 计算机系统的层次结构
    flask的宏 macro
    计算机组成原理习题
    flask模版继承和include
    flask自定义过滤器
  • 原文地址:https://www.cnblogs.com/mkdlf/p/7275454.html
Copyright © 2011-2022 走看看