码迷,mamicode.com
首页 > 其他好文 > 详细

校园商铺-2项目设计和框架搭建-9验证Service

时间:2019-09-21 19:18:59      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:with   ati   int   配置   config   autowired   tor   import   yar   

1. 新建接口

main: com.csj2018.o2o.service/AreaService.java

package com.csj2018.o2o.service;
import java.util.List;
import com.csj2018.o2o.entity.Area;
public interface AreaService {
    List<Area> getAreaList();
}

2. 新建实现类

main: com.csj2018.o2o.service.impl/AreaService.java

package com.csj2018.o2o.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.csj2018.o2o.dao.AreaDao;
import com.csj2018.o2o.entity.Area;
import com.csj2018.o2o.service.AreaService;
@Service
public class AreaServiceImpl implements AreaService{
    @Autowired
    private AreaDao areaDao;
    @Override
    public List<Area> getAreaList(){
        return areaDao.queryArea();
    }
}

3. 修改基类

test: com.csj2018.o2o/BaseTest.java

package com.csj2018.o2o;

import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
 * 配置spring和junit整合,junit启动式加载springIOC容器
 */
@RunWith(SpringJUnit4ClassRunner.class)
//告诉junit spring配置文件的位置
@ContextConfiguration({"classpath:spring/spring-dao.xml","classpath:spring/spring-service.xml"})
public class BaseTest {

}

4. 测试类

test: com.csj2018.o2o.service/AreaServiceTest.java

package com.csj2018.o2o.service;

import static org.junit.Assert.assertEquals;

import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.csj2018.o2o.BaseTest;
import com.csj2018.o2o.entity.Area;

public class AreaServiceTest extends BaseTest{
    @Autowired
    private AreaService areaService;
    @Test
    public void testGetAreaList() {
        List<Area> areaList = areaService.getAreaList();
        assertEquals("南苑",areaList.get(0).getAreaName());
    }

}

运行错误,待排查

校园商铺-2项目设计和框架搭建-9验证Service

标签:with   ati   int   配置   config   autowired   tor   import   yar   

原文地址:https://www.cnblogs.com/csj2018/p/11564003.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!