SpringBoot工程搭建好之后,完成相应业务逻辑,这个时候,我们需要测试。
正常情况,是服务启动,前端调用API,但是这个时候,后台服务开发人员想要自己测试,不使用http服务调用方式的情况,应该怎么做呢?
这里,我们使用的是SpringBoot:
1、引入相关的jar
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
|
2、在src/test/java下创建一个包,包下创建一个test类
如下:
我这里已经创建了一个service类:
下面继续对service的调用:
package com.kiki.kstore;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.alibaba.fastjson.JSON;
import com.kiki.kstore.entity.Permission;
import com.kiki.kstore.mapper.PermissionMapper;
/**
*
* unit test
*
* @ClassName: PropertiesTest
* @author kiki
* @date 2019年8月6日
* @version: V1.0
*/
@MapperScan(basePackages = “com.kiki.info.mapper”)
@RunWith(SpringRunner.class)
@SpringBootTest
public class PropertiesTest {
@Autowired
private PermissionMapper permissionMapper;
@Test
public void getList() throws Exception {
//完成对service的调用
List<Permission> list = permissionMapper.getAll();
System.out.println(JSON.toJSONString(list));
}
|