首页 > 学院 > 开发设计 > 正文

junit测试spring相关配置

2019-11-15 01:00:06
字体:
来源:转载
供稿:网友
junit测试sPRing相关配置

喜欢用Junit进行单元测试的时候,会碰到spring的配置文件无法映射,这样的问题我也碰到过,后来找到了解决办法,就是在类头部要增加注解,因为用junit测试的时候,是没有容器的放置相关配置,所以测试的时候会报空值错误。配置如下:

@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = { "classpath:/applicationContext.xml" })@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class })public class ServiceAttachmentServiceImplTest {    @Resource    private IServiceAttachmentService serviceAttachmentService;    @Test//测试SQL语句    public void testSQL() {        List<ServiceAttachment> atts = serviceAttachmentService                .getScrollData().getResultList();        }

之前一个朋友告诉我,这样配置后还是错误的,后来朋友告诉我,spring的配置文件如果用表达式的方式填充properties属性的话也是无效的,需直接把值写进入配置文件,这个问题我没试过,有碰到这种问题的朋友可以试试。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表