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