import com.luo.spring.service.MyService;
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;

@ContextConfiguration(locations = "classpath:spring01.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class SpringJunitTest01 {

    @Autowired
    MyService myService;

    @Test
    public void test01(){
        System.out.println(myService.add());
    }
}

注意:junit版本必须在4.12及以上