码迷,mamicode.com
首页 > 编程语言 > 详细

spring+junit单元测试

时间:2016-06-04 23:40:04      阅读:547      评论:0      收藏:0      [点我收藏+]

标签:

<1>读取文件:

    配置文件在classes下:locations = {"classpath*:/spring/applicationContext.xml"}

    配置文件在web-inf下:locations = {"file:web/WEB-INF/applicationContext.xml"}

<2>实例类:

   

package com.test;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.entity.User;
import com.service.impl.UserService;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"file:web/WEB-INF/applicationContext.xml"})
public class PageTest {

@Autowired
private UserService userService;


@Test
public void testPage(){
  //  add your  test  code
}
}

}

spring+junit单元测试

标签:

原文地址:http://www.cnblogs.com/meisp/p/5559775.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!