We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
目前单元测试使用 H2 作为测试用例的数据库, 但部署到生成环境时通常使用的是其他类型的数据库, 例如 MySQL, 这就导致在编写 SQL 语句时需要考虑兼容性的问题.
第一步,编写包含日期格式的 SQL
第二步,单元测试使用的 H2 使用的函数是 https://h2database.com/html/functions.html#formatdatetime
第三步,生产环境使用的 MySQL 使用的函数是 https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format
第四步, mapper 上无法编写两边都兼容的 Select 语句.
The text was updated successfully, but these errors were encountered:
应当鼓励开发者使用生成环境相同的数据库类型进行单元测试, 避免破坏 不可变技术设施 原则.
Sorry, something went wrong.
https://blog.csdn.net/weixin_42710740/article/details/121742580 可以通过这个方式,曲线救国。
单元测试,要考虑独立运行,不建议跑一个 mysql 进程哈。 h2 作为内存数据库,基本算业内的最佳实践啦。包括 spring 也是这么推荐的噢
YunaiV
No branches or pull requests
基本信息
你猜测可能的原因
目前单元测试使用 H2 作为测试用例的数据库, 但部署到生成环境时通常使用的是其他类型的数据库, 例如 MySQL, 这就导致在编写 SQL 语句时需要考虑兼容性的问题.
复现步骤
第一步,编写包含日期格式的 SQL
第二步,单元测试使用的 H2 使用的函数是 https://h2database.com/html/functions.html#formatdatetime
第三步,生产环境使用的 MySQL 使用的函数是 https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format
第四步, mapper 上无法编写两边都兼容的 Select 语句.
报错信息
The text was updated successfully, but these errors were encountered: