zl程序教程

您现在的位置是:首页 >  后端

当前栏目

spring 整合junit进行测试详解编程语言

Springjunit测试编程语言 详解 进行 整合
2023-06-13 09:11:49 时间

    如果想让junit和spring容器环境无缝对接的话,可以使用如下方式:

 

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; 

 @Test 

 public void addCron() { 

 try 

 cronService.addCron(); 

 } catch (Exception e) 

 e.printStackTrace(); 

}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/18186.html

cjavaxml