IDE环境 Eclipse
导入依赖包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
创建测试类
右键需要测试的类,选择Other

选择创建JUnit Test Case


选择创建目录,创建测试类
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON;
import com.jzfyjt.framework.core.base.controller.result.Result;
import com.jzfyjt.jzap.startup.JzapApiApplication;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { JzapApiApplication.class })
class SysUserServiceTest {
@Autowired
SysUserService sysUserService;
@Test
void test() {
// success
System.out.println("第一次获取");
Result<Object> r = sysUserService.getSysUserById("0143");
System.out.println(JSON.toJSONString(r));
}
}
@SpringBootTest(classes = { JzapApiApplication.class })指定Springboot的启动类,此处至关重要
网友评论