Spring整合JUnit单元测试

 

依赖spring的spring-test-4.2.4.RELEASE.jar包

测试代码:

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;

import com.spring.demo04.UserService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class Demo {
    
    @Autowired
    private UserService userService;
    
    @Test
    public void run() {
        userService.save();
    }

}

运行结果:

 

posted @ 2019-10-05 03:32  Jumpkin1122  阅读(160)  评论(0编辑  收藏  举报