添加 api 单元测试模板.
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package ${currentPackage};
|
||||
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.ops.framework.test.core.base.BaseUnitTest;
|
||||
import com.orion.ops.framework.test.core.utils.EntityRandoms;
|
||||
import ${package.ServiceImpl}.*;
|
||||
#foreach($pkg in ${customProviderFilePackages})
|
||||
import ${pkg}.*;
|
||||
#end
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 对外服务单元测试
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/8/23 10:36
|
||||
*/
|
||||
@Slf4j
|
||||
@Import({${type}ApiImpl.class, ${type}ServiceImpl.class})
|
||||
public class ${type}ApiImplTests extends BaseUnitTest {
|
||||
|
||||
@Resource
|
||||
private ${type}Api ${typeLower}Api;
|
||||
|
||||
private static Long lastId;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void create${type}Test() {
|
||||
${type}CreateDTO req = EntityRandoms.random(${type}CreateDTO.class);
|
||||
lastId = ${typeLower}Api.create${type}(req);
|
||||
assertNotNull(lastId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
public void update${type}ByIdTest() {
|
||||
${type}UpdateDTO req = EntityRandoms.random(${type}UpdateDTO.class);
|
||||
req.setId(lastId);
|
||||
Integer effect = ${typeLower}Api.update${type}ById(req);
|
||||
assertEquals(effect, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
public void get${type}ByIdTest() {
|
||||
${type}DTO row = ${typeLower}Api.get${type}ById(lastId);
|
||||
assertNotNull(row);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
public void get${type}ByIdListTest() {
|
||||
List<${type}DTO> rows = ${typeLower}Api.get${type}ByIdList(Lists.of(lastId));
|
||||
assertFalse(rows.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
public void get${type}ListTest() {
|
||||
List<${type}DTO> rows = ${typeLower}Api.get${type}List(new ${type}QueryDTO());
|
||||
assertFalse(rows.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
public void get${type}CountTest() {
|
||||
Long count = ${typeLower}Api.get${type}Count(new ${type}QueryDTO());
|
||||
assertEquals(count, 1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
public void delete${type}ByIdTest() {
|
||||
Integer effect = ${typeLower}Api.delete${type}ById(lastId);
|
||||
assertEquals(effect, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
public void batchDelete${type}ByIdListTest() {
|
||||
Integer effect = ${typeLower}Api.batchDelete${type}ByIdList(Lists.of(lastId));
|
||||
assertEquals(effect, 0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.ops.framework.test.core.base.BaseUnitTest;
|
||||
import com.orion.ops.framework.test.core.utils.EntityRandoms;
|
||||
import ${package.Service}.*;
|
||||
#foreach($pkg in ${customModuleFilePackages})
|
||||
import ${pkg}.*;
|
||||
#end
|
||||
@@ -26,7 +27,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
*/
|
||||
@Slf4j
|
||||
@Import(${type}ServiceImpl.class)
|
||||
public class ${type}ServiceTests extends BaseUnitTest {
|
||||
public class ${type}ServiceImplTests extends BaseUnitTest {
|
||||
|
||||
@Resource
|
||||
private ${type}Service ${typeLower}Service;
|
||||
Reference in New Issue
Block a user