mirror of
https://gitee.com/lakernote/easy-admin.git
synced 2026-09-03 05:33:47 +08:00
【优化】增加UT依赖和DEMO
This commit is contained in:
27
pom.xml
27
pom.xml
@@ -79,13 +79,6 @@
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- aop -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -196,6 +189,26 @@
|
||||
<version>2.2.9</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- PowerMock Mockito2 API -->
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito2</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.laker.admin.module.sys.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.laker.admin.config.LakerConfig;
|
||||
import com.laker.admin.framework.model.PageResponse;
|
||||
import com.laker.admin.module.sys.service.ISysRoleService;
|
||||
import com.laker.admin.module.sys.service.ISysUserRoleService;
|
||||
import com.laker.admin.module.sys.service.ISysUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
/**
|
||||
* @author : [laker]
|
||||
* @className : SysUserControllerTest
|
||||
* @description : [powermock测试demo,测试类包目录应与原类目录一致,方便统计单元测试覆盖率]
|
||||
* @date : 2022年04月16日 17:52
|
||||
* @createTime : [2022/4/16 17:52]
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class) // 告诉JUnit使用PowerMockRunner进行测试
|
||||
@PrepareForTest({SysUserController.class}) // 所有需要测试的类列在此处
|
||||
@Slf4j
|
||||
public class SysUserControllerTest {
|
||||
/**
|
||||
* 需要单元测试的类
|
||||
*/
|
||||
@InjectMocks
|
||||
SysUserController sysUserController;
|
||||
/**
|
||||
* 单元测试类依赖的类
|
||||
*/
|
||||
@Mock
|
||||
ISysUserService sysUserService;
|
||||
@Autowired
|
||||
ISysRoleService sysRoleService;
|
||||
@Autowired
|
||||
ISysUserRoleService sysUserRoleService;
|
||||
@Autowired
|
||||
LakerConfig lakerConfig;
|
||||
|
||||
@Test
|
||||
public void pageAll() {
|
||||
/** 录制 mock操作 */
|
||||
when(sysUserService.page(any(), any()))
|
||||
.thenReturn(new Page<>());
|
||||
/** 执行操作 */
|
||||
//执行mock查询操作
|
||||
PageResponse result = sysUserController.pageAll(1, 2, 3L, "laker");
|
||||
log.info(result.toString());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user