首页 > 编程语言 > 详细

junit spring 注解 单元测试

时间:2014-11-12 19:45:15      阅读:383      评论:0      收藏:0      [点我收藏+]

直接上代码包依赖请自行加入maven添加依赖很方便

1、TestBase.java

package com.test;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("junit")
@ContextConfiguration(locations = {
		"classpath*:spring/applicationContext.xml",
        "classpath*:com/ibm/uam/**/META-INF/beans.xml",
        "classpath*:com/ibm/common/**/META-INF/beans.xml",
        "classpath*:spring/spring-mvc.xml"
		})
public class TestBase {
	protected Log logger = LogFactory.getLog(TestBase.class);

	@Before
	// 一些公用的“初始化”代码
	public void before() {
		
	}
}
2、JobTest.java

package com.test;

import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;

import com.alibaba.fastjson.JSONObject;
import com.userorg.entity.Job;
import com.userorg.service.JobService;

public class JobTest extends TestBase {
@Resource
private JobService jobService;
@Test
public void sendQTest(){
	List<Job> list = jobService.findAllJobs();
	System.out.println(JSONObject.toJSON(list));
	
}

}


junit spring 注解 单元测试

原文:http://blog.csdn.net/lantianzhange/article/details/41048355

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!