在 Maven/Junit/DBUnit 项目集成测试之前/之后创建/删除数据库的最佳方法?
我见过有人使用 maven-sql-plugin 来做到这一点。但这似乎是一个更适合 DBUnit 的任务......也许在整个测试套件的开始。
这里的最佳实践是什么?
I've seen some people use the maven-sql-plugin to do this. But it seems like a task that is better suited for DBUnit....perhaps at the beginning of an entire test suite.
What's the best practice here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用 Maven SQL 插件
你最好使用它并确保在测试之前创建并填充,然后在测试之后删除。如果测试失败并留下数据库处于某种不一致的状态。
I use the Maven SQL Plugin
You're much better off using it and making sure that you create and populate before your tests and then drop after your tests. You'll also want to use create or replace, or drop if exists in your creation script (assuming your database supports it) in the event that a test fails and leaves the database in some inconsistent state.
我花了一些时间摆弄,但我让它删除、创建和创建 H2 和 MySQL 的模式。对于 Oracle 和 SQL*Server 2008,仍然需要完成它。我将确切的 DROP 和 CREATE 命令塞进属性中,在某些情况下(例如 H2)需要完全跳过创建数据库。它看起来是这样的:
It took some fiddling around, but I got it to drop, create, and create the schema for H2 and MySQL. Still need to finish it for Oracle and SQL*Server 2008. I tucked the exact DROP and CREATE commands into properties and in some cases (such as H2) needed to skip the create database altogether. Here is what it looks like: