spring的單元測試


import javax.annotation.Resource;

import org.junit.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/ApplicationContext-dao.xml")
public class JunitTest extends AbstractJUnit4SpringContextTests {
	
	@Resource(name = "handler")
	private handler handler;
	
	private int id;
	private int userId;
	
	@Before
	public void init(){
		id=599;
		userId = 368469;
	}
	
	@After
	public void destroy(){
		
	}
	
	@Test
	public void test() {
		Assert.assertNotNull(this.handler);
		
		try {
			System.out.println(handler.queryAddressById(id, userId));
		} catch (Exception e) {
			System.out.println(e);
		}
	}
}

發佈了50 篇原創文章 · 獲贊 5 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章