我希望为我们基于 Seam Framework 的网站的内部搜索引擎编写测试,该引擎使用 Hibernate + Lucene 索引(在 DB2 上)进行查询。当项目的数据模型非常复杂(考虑到实体关系和字段约束)时,在运行 TestNG 套件之前填充数据源的最佳解决方案是什么?对于某些测试用例,至少有十几个数据库表需要彼此相关的行,以便遵守数据模型的约束。理想情况下,将使用 Hypersonic,因为内存中的使用将缩短我们的构建过程的运行时间。
希望我的问题很清楚,因为如果不抛出大量描述性文本和专有代码,很难对我的问题形成完整的描述。基本上,考虑到我们已经编写的数据模型和 populate.sql 脚本,以编程方式创建每个实体(通过 Hibernate 的 Home 对象实例化所有对象、设置每个属性、持久化到数据源并在 FacesRequest @Test 中提交事务)太笨重了(并且在 DB2 上执行以在本地运行 JBoss 托管的网站)无法在 Hypersonic 上使用!我在网上或书中遇到的每个 TestNG 示例都包含极其简单的数据集,这些数据集并没有表明解决我的问题的明确方法。
I wish to write tests for our Seam Framework-based web site's internal search engine that uses Hibernate + Lucene indexing (on DB2) for queries. What is the best solution for populating the data source before the TestNG suite is run when the project's data model is quite complex considering entity relationships and field constraints? For some test cases, at least a dozen database tables would require rows relating to each other in order to adhere to the data model's constraints. Ideally Hypersonic would be used since in-memory usage will shorten our build process' running time.
Hopefully my question is clear as it's difficult to formulate a complete picture of my problem without throwing up a massive wall of descriptive text and proprietary code. Basically, creating each entity programmatically (instantiating all objects via Hibernate's Home object, setting each property, persisting to data source, and committing transaction in a FacesRequest @Test) is too unwieldy given the data model and the populate.sql script we already have written (and is executed on DB2 for running our JBoss-hosted web site locally) can't be used on Hypersonic! And every TestNG example I come across online or in books contain brutally simple data sets that don't indicate a clear approach to my problem.
发布评论
评论(2)
要创建复杂的数据,同时隐藏复杂的设置,我的建议是使用描述的构建器模式此处 它允许您创建诸如“
关于 h2 和 db2 互操作性”之类的内容。最先进的 POJO in Action 书中说
虽然您的问题涉及 Hypersonic,但 H2 功能包括
也许它可以解决你想要的。尝试一下。
可以使用不同的方法来填充测试所需的数据。 XUnit 夹具设置模式 解释了一个有用的指南。
其他可以帮助您的工具是
To create your complex data and, at the same time, hide complex setup, my advice is to use builder pattern which is described here It allows you to create stuff like
About h2 and db2 interoperability. State of the art POJO in Action book says
Although your question draws Hypersonic, H2 features includes
Maybe it can solve what you want. Try it.
Differents approachs can be used to populate the data needed to test. A useful guide is explained by XUnit Fixture Setup Patterns.
Other tools which can help you is
如果您想重用 SQL 脚本,可以尝试使用 DB2 兼容模式的 H2,按照@Arthur的建议。如果它不起作用,请尝试 JavaDB/Derby,它与 DB2 的语言兼容,也可以在“内存中”使用。
但如果脚本很大,恐怕测试会很慢。在这种情况下,使用 DbUnit 和较小的数据集可能是一种替代方案。看看内置的
DBUnitSeamTest
和使用 Seam、DBUnit 和 TestNG 进行功能测试。如果您采用 DbUnit 方式,则可以使用 databene benerator 之类的工具来 生成模拟数据,然后将它们转储为 DbUnit 数据集(有 一个 Eclipse 插件 来简化此任务)。
If you want to reuse your SQL script, you could try H2 with the DB2 compatibility mode, as suggested by @Arthur. If it doesn't work, try JavaDB/Derby, which is DB2's language compatible and can also be used "in-memory".
But if the script is huge, I'm afraid tests will be pretty slow. In that case, using DbUnit and smaller dataset could be an alternative. Have a look at the built-in
DBUnitSeamTest
and Functional testing with Seam, DBUnit, and TestNG.And if you go the DbUnit way, you could use a tool like databene benerator to generate mock data and then dump them as DbUnit dataset (there is an eclipse plugin to ease this task).