1. 程式人生 > >maven+spring+hibernate情況下如何使用junit測試

maven+spring+hibernate情況下如何使用junit測試

import java.util.List;


import javax.annotation.Resource;


import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;


import com.qky.dao.utilDao.RegionDao;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:spring*.xml"})
@Transactional
public class UserTest {
	@Resource
	private RegionDao regionDao;
	@Test
	public void testmain() {
		List list=regionDao.getRegionByParent("0");
		System.out.println(list);
		System.out.println(list.isEmpty());
		for (Object object : list) {
			System.out.println(object);
		}
	}
}
其他配置不動,在測試類裡面這樣寫,測試成功