فهرست منبع

【功能优化】INFRA:代码生成时,默认禁用单元测试的生成,更符合大家的习惯

YunaiV 8 ماه پیش
والد
کامیت
805f80c36a

+ 6 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/codegen/config/CodegenProperties.java

@@ -34,4 +34,10 @@ public class CodegenProperties {
     @NotNull(message = "代码生成的前端类型不能为空")
     private Integer frontType;
 
+    /**
+     * 是否生成单元测试
+     */
+    @NotNull(message = "是否生成单元测试不能为空")
+    private Boolean unitTestEnable;
+
 }

+ 5 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java

@@ -398,6 +398,11 @@ public class CodegenEngine {
         Map<String, String> templates = new LinkedHashMap<>();
         templates.putAll(SERVER_TEMPLATES);
         templates.putAll(FRONT_TEMPLATES.row(frontType));
+        // 如果禁用单元测试,则移除对应的模版
+        if (Boolean.FALSE.equals(codegenProperties.getUnitTestEnable())) {
+            templates.remove(javaTemplatePath("test/serviceTest"));
+            templates.remove("codegen/sql/h2.vm");
+        }
         return templates;
     }
 

+ 1 - 0
yudao-server/src/main/resources/application.yaml

@@ -246,6 +246,7 @@ yudao:
     base-package: ${yudao.info.base-package}
     db-schemas: ${spring.datasource.dynamic.datasource.master.name}
     front-type: 20 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类
+    unit-test-enable: false # 是否生成单元测试
   tenant: # 多租户相关配置项
     enable: true
     ignore-urls: