From 88660caec885a6e67fa083efbd71a9314ae0b7a6 Mon Sep 17 00:00:00 2001 From: mateaix <57164338+mateaix@users.noreply.github.com> Date: Sat, 1 Aug 2026 20:34:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(test):=20=E7=94=A8=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=88=9D=E5=A7=8B=E5=8C=96=20system-setting?= =?UTF-8?q?=20=E5=88=97=E5=90=8D=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TableInfoHelper 写的是 JVM 级静态列名缓存,三个测试用原生 MyBatis Configuration 初始化,默认把属性映射成 camelCase 列名(settingKey 而非 setting_key),后写覆盖 先写,导致同一 surefire fork 内该实体的后续查询全部生成非法 SQL。 表现为 TeamControllerTest 抛 BadSqlGrammarException —— 而它本身并不查库: R.ok() 通过先前 Spring 上下文测试装上的静态 I18nService 解析消息,后者会读 mate_system_setting 的语言设置。单跑该类通过,全量跑失败。 --- .../mate/system/service/SystemSettingBoolApiTest.java | 10 ++++++++-- .../service/SystemSettingServiceCatalogTest.java | 10 ++++++++-- .../service/SystemSettingWorkspaceStorageRootTest.java | 10 ++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/mateclaw-server/src/test/java/vip/mate/system/service/SystemSettingBoolApiTest.java b/mateclaw-server/src/test/java/vip/mate/system/service/SystemSettingBoolApiTest.java index f79f34d3..77e752e3 100644 --- a/mateclaw-server/src/test/java/vip/mate/system/service/SystemSettingBoolApiTest.java +++ b/mateclaw-server/src/test/java/vip/mate/system/service/SystemSettingBoolApiTest.java @@ -1,8 +1,8 @@ package vip.mate.system.service; +import com.baomidou.mybatisplus.core.MybatisConfiguration; import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; import org.apache.ibatis.builder.MapperBuilderAssistant; -import org.apache.ibatis.session.Configuration; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -40,8 +40,14 @@ class SystemSettingBoolApiTest { @BeforeAll static void initTableInfo() { + // MybatisConfiguration, not the plain MyBatis Configuration: the column + // cache TableInfoHelper installs is static and JVM-wide, and a plain + // Configuration maps properties to camelCase columns (settingKey rather + // than setting_key). Seeding it that way poisons every later query on + // this entity in the same surefire fork, including ones issued through + // a Spring context. TableInfoHelper.initTableInfo( - new MapperBuilderAssistant(new Configuration(), ""), + new MapperBuilderAssistant(new MybatisConfiguration(), ""), SystemSettingEntity.class); } diff --git a/mateclaw-server/src/test/java/vip/mate/system/service/SystemSettingServiceCatalogTest.java b/mateclaw-server/src/test/java/vip/mate/system/service/SystemSettingServiceCatalogTest.java index 25079662..25eb92e9 100644 --- a/mateclaw-server/src/test/java/vip/mate/system/service/SystemSettingServiceCatalogTest.java +++ b/mateclaw-server/src/test/java/vip/mate/system/service/SystemSettingServiceCatalogTest.java @@ -1,8 +1,8 @@ package vip.mate.system.service; +import com.baomidou.mybatisplus.core.MybatisConfiguration; import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; import org.apache.ibatis.builder.MapperBuilderAssistant; -import org.apache.ibatis.session.Configuration; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -44,8 +44,14 @@ class SystemSettingServiceCatalogTest { @BeforeAll static void initTableInfo() { + // MybatisConfiguration, not the plain MyBatis Configuration: the column + // cache TableInfoHelper installs is static and JVM-wide, and a plain + // Configuration maps properties to camelCase columns (settingKey rather + // than setting_key). Seeding it that way poisons every later query on + // this entity in the same surefire fork, including ones issued through + // a Spring context. TableInfoHelper.initTableInfo( - new MapperBuilderAssistant(new Configuration(), ""), + new MapperBuilderAssistant(new MybatisConfiguration(), ""), SystemSettingEntity.class); } diff --git a/mateclaw-server/src/test/java/vip/mate/system/service/SystemSettingWorkspaceStorageRootTest.java b/mateclaw-server/src/test/java/vip/mate/system/service/SystemSettingWorkspaceStorageRootTest.java index cc789a6d..e75d479a 100644 --- a/mateclaw-server/src/test/java/vip/mate/system/service/SystemSettingWorkspaceStorageRootTest.java +++ b/mateclaw-server/src/test/java/vip/mate/system/service/SystemSettingWorkspaceStorageRootTest.java @@ -1,8 +1,8 @@ package vip.mate.system.service; +import com.baomidou.mybatisplus.core.MybatisConfiguration; import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; import org.apache.ibatis.builder.MapperBuilderAssistant; -import org.apache.ibatis.session.Configuration; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -56,8 +56,14 @@ class SystemSettingWorkspaceStorageRootTest { @BeforeAll static void initTableInfo() { + // MybatisConfiguration, not the plain MyBatis Configuration: the column + // cache TableInfoHelper installs is static and JVM-wide, and a plain + // Configuration maps properties to camelCase columns (settingKey rather + // than setting_key). Seeding it that way poisons every later query on + // this entity in the same surefire fork, including ones issued through + // a Spring context. TableInfoHelper.initTableInfo( - new MapperBuilderAssistant(new Configuration(), ""), + new MapperBuilderAssistant(new MybatisConfiguration(), ""), SystemSettingEntity.class); }