导包

    1. <dependency>
    2. <groupId>org.springframework.boot</groupId>
    3. <artifactId>spring-boot-starter-test</artifactId>
    4. <scope>test</scope>
    5. </dependency>
    6. <dependency>
    7. <groupId>junit</groupId>
    8. <artifactId>junit</artifactId>
    9. <scope>test</scope>
    10. </dependency>
    1. import cn.hutool.json.JSONUtil;
    2. import cn.hutool.log.Log;
    3. import cn.hutool.log.LogFactory;
    4. import com.github.pagehelper.PageHelper;
    5. import com.hn.Application;
    6. import com.hn.common.utils.sql.SqlUtil;
    7. import org.junit.runner.RunWith;
    8. import org.springframework.boot.test.context.SpringBootTest;
    9. import org.springframework.test.context.junit4.SpringRunner;
    10. import java.util.List;
    11. /**
    12. * web单元测试继承该类即可
    13. */
    14. @RunWith(SpringRunner.class)
    15. @SpringBootTest(classes = Application.class)
    16. public abstract class TesterBase {
    17. public static final Integer userId = 1;
    18. private static final Log log = LogFactory.get("TesterBase");
    19. public void toJsonStr(Object o) {
    20. log.info("### " + JSONUtil.formatJsonStr(JSONUtil.toJsonStr(o)));
    21. }
    22. protected void startPage(String orderBy) {
    23. Integer pageNum = 1;
    24. Integer pageSize = 20;
    25. String orderByValue = SqlUtil.escapeOrderBySql(orderBy);
    26. PageHelper.startPage(pageNum, pageSize, orderByValue);
    27. }
    28. public void assertSize(List list) {
    29. assert list != null && list.size() > 0;
    30. }
    31. }

    image.png