注意 1.类上面需要加两个注解
2:Caused by: java.lang.IllegalStateException: SpringJUnit4ClassRunner requires JUnit 4.12 or higher.
举个栗子
1 package com.qianfeng.test;
2
3 import com.qianfeng.restfull.beans.TbHotel;
4 import com.qianfeng.restfull.dao.IHotelDAO;
5 import org.junit.Test;
6 import org.junit.runner.RunWith;
7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.test.context.ContextConfiguration;
9 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10
11 import java.util.List;
12
13 @RunWith(SpringJUnit4ClassRunner.class)
14 @ContextConfiguration("classpath:spring.xml")
15 public class SpringTest {
16
17 @Autowired
18 private IHotelDAO hotelDAO;
19
20 @Test
21 public void testCase1(){
22 try {
23 List<TbHotel> hotelList = hotelDAO.queryHotelByPage(0);
24 System.out.println(hotelList);
25 } catch (Exception e) {
26 e.printStackTrace();
27 }
28 }
29 }