package com.paradise;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import org.springframework.test.context.transaction.TransactionConfiguration;import org.springframework.transaction.annotation.Transactional;/** * 单元测试 基类 * 注意事项: * 1. 需要修改applicationContext.xml 中 jdbc 相关配置文件的路径,否则会找不到 * 2. 事务注解不能去掉,否则会污染数据库 * 3. @Test 注解的空方法需要保留,否则maven-install 会报错 java.lang.Exception: No runnable methods * * @author Paradise */@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = {"classpath:applicationContext.xml"})@Transactional@TransactionConfigurationpublic class BaseJunit4Test { @Test public void run() { }}
package com.paradise.record;import com.huiwang.base.exception.ServiceException;import com.huiwang.record.service.IRecordService;import com.huiwang.record.vo.ReviewRecordBean;import com.paradise.BaseJunit4Test;import org.junit.Test;import org.springframework.beans.factory.annotation.Autowired;import java.util.List;import java.util.Map;/** * 普查记录,复查记录相关单元测试 * * @author Paradise */public class RecordTest extends BaseJunit4Test { @Autowired private IRecordService recordService; /** * 查询复查记录修改 * * @date 2019-9-2 */ @Test public void getRecordList() { ReviewRecordBean bean = new ReviewRecordBean(); bean.setPageNum("1"); bean.setPageSize("10"); bean.setBasicId(3L); try { Map<String, Object> map = recordService.getReviewRecordListByPage("9", "0", bean); System.out.println(map.get("total")); int total = Integer.parseInt(String.valueOf(map.get("total"))); List<ReviewRecordBean> list = (List<ReviewRecordBean>) map.get("list"); System.out.print(list.size()); assert list.size() == total; } catch (ServiceException e) { e.printStackTrace(); } }}