diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineAbstractTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineAbstractTest.java index 588f2b08b9..f8b778e30c 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineAbstractTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineAbstractTest.java @@ -31,6 +31,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; */ public abstract class CodegenEngineAbstractTest extends BaseMockitoUnitTest { + public String resourcesPath = ""; // 测试文件资源目录 + public static final String OS_NAME = System.getProperty("os.name").toLowerCase().replace(" ", ""); // 操作系统名称 + @InjectMocks protected CodegenEngine codegenEngine; @@ -41,6 +44,10 @@ public abstract class CodegenEngineAbstractTest extends BaseMockitoUnitTest { @BeforeEach public void setUp() { codegenEngine.initGlobalBindingMap(); + // 获取测试文件 resources 路径 + String absolutePath = FileUtil.getAbsolutePath("application-unit-test.yaml"); + // 系统不一样生成的文件也有差异,那就各自生成各自的 + resourcesPath = absolutePath.split("/target")[0] + "/src/test/resources/codegen/" + OS_NAME; } protected static CodegenTableDO getTable(String name) { @@ -73,14 +80,14 @@ public abstract class CodegenEngineAbstractTest extends BaseMockitoUnitTest { @SuppressWarnings("rawtypes") protected static void assertResult(Map result, String path) { - String assertContent = ResourceUtil.readUtf8Str(path + "/assert.json"); + String assertContent = ResourceUtil.readUtf8Str("codegen/" + OS_NAME + path + "/assert.json"); List asserts = JsonUtils.parseArray(assertContent, HashMap.class); assertEquals(asserts.size(), result.size()); // 校验每个文件 asserts.forEach(assertMap -> { String contentPath = (String) assertMap.get("contentPath"); String filePath = (String) assertMap.get("filePath"); - String content = ResourceUtil.readUtf8Str(path + "/" + contentPath); + String content = ResourceUtil.readUtf8Str("codegen/" + OS_NAME + path + "/" + contentPath); assertEquals(content, result.get(filePath), filePath + ":不匹配"); }); } @@ -91,7 +98,7 @@ public abstract class CodegenEngineAbstractTest extends BaseMockitoUnitTest { * 【调试使用】将生成的代码,写入到文件 * * @param result 生成的代码 - * @param path 写入文件的路径 + * @param path 写入文件的路径 */ protected void writeFile(Map result, String path) { // 生成压缩包 @@ -106,7 +113,7 @@ public abstract class CodegenEngineAbstractTest extends BaseMockitoUnitTest { /** * 【调试使用】将生成的结果,写入到文件 * - * @param result 生成的代码 + * @param result 生成的代码 * @param basePath 写入文件的路径(绝对路径) */ protected void writeResult(Map result, String basePath) { @@ -121,7 +128,7 @@ public abstract class CodegenEngineAbstractTest extends BaseMockitoUnitTest { FileUtil.writeUtf8String(fileContent, basePath + "/" + contentPath); }); // 写入 assert.json 文件 - FileUtil.writeUtf8String(JsonUtils.toJsonPrettyString(asserts), basePath +"/assert.json"); + FileUtil.writeUtf8String(JsonUtils.toJsonPrettyString(asserts), basePath + "/assert.json"); } } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue2Test.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue2Test.java index a8be741207..94d24bed14 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue2Test.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue2Test.java @@ -11,7 +11,6 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -// TODO @puhui999:单测需要 fix /** * {@link CodegenEngine} 的 Vue2 + Element UI 单元测试 * @@ -30,9 +29,10 @@ public class CodegenEngineVue2Test extends CodegenEngineAbstractTest { // 调用 Map result = codegenEngine.execute(table, columns, null, null); + // 生成测试文件 + //writeResult(result, resourcesPath + "/vue2_one"); // 断言 - assertResult(result, "codegen/vue2_one"); -// writeResult(result, "/root/ruoyi-vue-pro/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one"); + assertResult(result, "/vue2_one"); } @Test @@ -45,25 +45,26 @@ public class CodegenEngineVue2Test extends CodegenEngineAbstractTest { // 调用 Map result = codegenEngine.execute(table, columns, null, null); + // 生成测试文件 + //writeResult(result, resourcesPath + "/vue2_tree"); // 断言 - assertResult(result, "codegen/vue2_tree"); -// writeResult(result, "/root/ruoyi-vue-pro/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree"); + assertResult(result, "/vue2_tree"); // writeFile(result, "/Users/yunai/test/demo66.zip"); } @Test public void testExecute_vue2_master_normal() { - testExecute_vue2_master(CodegenTemplateTypeEnum.MASTER_NORMAL, "codegen/vue2_master_normal"); + testExecute_vue2_master(CodegenTemplateTypeEnum.MASTER_NORMAL, "/vue2_master_normal"); } @Test public void testExecute_vue2_master_erp() { - testExecute_vue2_master(CodegenTemplateTypeEnum.MASTER_ERP, "codegen/vue2_master_erp"); + testExecute_vue2_master(CodegenTemplateTypeEnum.MASTER_ERP, "/vue2_master_erp"); } @Test public void testExecute_vue2_master_inner() { - testExecute_vue2_master(CodegenTemplateTypeEnum.MASTER_INNER, "codegen/vue2_master_inner"); + testExecute_vue2_master(CodegenTemplateTypeEnum.MASTER_INNER, "/vue2_master_inner"); } private void testExecute_vue2_master(CodegenTemplateTypeEnum templateType, @@ -89,9 +90,10 @@ public class CodegenEngineVue2Test extends CodegenEngineAbstractTest { // 调用 Map result = codegenEngine.execute(table, columns, Arrays.asList(contactTable, teacherTable), Arrays.asList(contactColumns, teacherColumns)); + // 生成测试文件 + //writeResult(result, resourcesPath + path); // 断言 assertResult(result, path); -// writeResult(result, "/root/ruoyi-vue-pro/yudao-module-infra/yudao-module-infra-biz/src/test/resources/" + path); // writeFile(result, "/Users/yunai/test/demo11.zip"); } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue3Test.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue3Test.java index 56ad78aec2..ce745c9100 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue3Test.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue3Test.java @@ -27,9 +27,10 @@ public class CodegenEngineVue3Test extends CodegenEngineAbstractTest { // 调用 Map result = codegenEngine.execute(table, columns, null, null); + // 生成测试文件 + //writeResult(result, resourcesPath + "/vue3_one"); // 断言 - assertResult(result, "codegen/vue3_one"); -// writeResult(result, "/root/ruoyi-vue-pro/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_one"); + assertResult(result, "/vue3_one"); } @Test @@ -42,25 +43,26 @@ public class CodegenEngineVue3Test extends CodegenEngineAbstractTest { // 调用 Map result = codegenEngine.execute(table, columns, null, null); + // 生成测试文件 + //writeResult(result, resourcesPath + "/vue3_tree"); // 断言 - assertResult(result, "codegen/vue3_tree"); -// writeResult(result, "/root/ruoyi-vue-pro/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_tree"); + assertResult(result, "/vue3_tree"); // writeFile(result, "/Users/yunai/test/demo66.zip"); } @Test public void testExecute_vue3_master_normal() { - testExecute_vue3_master(CodegenTemplateTypeEnum.MASTER_NORMAL, "codegen/vue3_master_normal"); + testExecute_vue3_master(CodegenTemplateTypeEnum.MASTER_NORMAL, "/vue3_master_normal"); } @Test public void testExecute_vue3_master_erp() { - testExecute_vue3_master(CodegenTemplateTypeEnum.MASTER_ERP, "codegen/vue3_master_erp"); + testExecute_vue3_master(CodegenTemplateTypeEnum.MASTER_ERP, "/vue3_master_erp"); } @Test public void testExecute_vue3_master_inner() { - testExecute_vue3_master(CodegenTemplateTypeEnum.MASTER_INNER, "codegen/vue3_master_inner"); + testExecute_vue3_master(CodegenTemplateTypeEnum.MASTER_INNER, "/vue3_master_inner"); } private void testExecute_vue3_master(CodegenTemplateTypeEnum templateType, @@ -86,10 +88,11 @@ public class CodegenEngineVue3Test extends CodegenEngineAbstractTest { // 调用 Map result = codegenEngine.execute(table, columns, Arrays.asList(contactTable, teacherTable), Arrays.asList(contactColumns, teacherColumns)); + // 生成测试文件 + //writeResult(result, resourcesPath + path); // 断言 assertResult(result, path); -// writeResult(result, "/root/ruoyi-vue-pro/yudao-module-infra/yudao-module-infra-biz/src/test/resources/" + path); -// writeFile(result, "/Users/yunai/test/demo11.zip"); + // writeFile(result, "/Users/yunai/test/demo11.zip"); } }