spring 整合junit进行测试
生活随笔
收集整理的這篇文章主要介紹了
spring 整合junit进行测试
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
? ? 如果想讓junit和spring容器環(huán)境無縫對(duì)接的話,可以使用如下方式:
??
import com.jd.ptest.service.ICronService; 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 static org.junit.Assert.*;@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:applicationContext.xml"}) //此處讀取spring的配置文件 public class CronServiceImplTest {@Autowired@SuppressWarnings("all")ICronService cronService;@Testpublic void addCron() {try{cronService.addCron();} catch (Exception e){e.printStackTrace();}} }?
轉(zhuǎn)載于:https://www.cnblogs.com/onmyway20xx/p/9010104.html
總結(jié)
以上是生活随笔為你收集整理的spring 整合junit进行测试的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos7 以上和以下版本设置
- 下一篇: 开源作品ThinkJDBC—一行代码搞定