在调试时检查内存hsqldb [英] Inspect in memory hsqldb while debugging

查看:97
本文介绍了在调试时检查内存hsqldb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在内存中使用hdsqldb来运行针对数据库运行的junit测试。在通过弹簧配置运行每个测试之前设置db。一切正常。
现在,当测试失败时,可以方便地检查内存数据库中的值。这可能吗?如果是这样的话?
我们的网址是:


jdbc.url = jdbc:hsqldb:mem:testdb; sql.enforce_strict_size = true


每次测试后数据库都会被销毁。但是当调试器运行时,数据库也应该仍然存在。我尝试连接sqldb databaseManager。这有效,但我没有看到任何表或数据。任何帮助都非常感谢!

解决方案

HSQL在内存中,所以当你说你正在连接SQLDB数据库管理器时,你不是 - 而是连接到SQLDB数据库管理器的内存空间中的另一个数据库,而不是单元测试的内存空间中的数据库。这就是SQLDB数据库管理器中的数据库为空的原因。



您可以使用 org.hsqldb.Server 此处所述。



虽然 org.hsqldb.Server 类通常用于启动单独的进程,但您可以实例化并在单元测试中配置它,这应该允许远程进程连接和查询数据库。



或者,你必须编写某种转储功能,根据需要在单元测试中调用。



另外,在单元测试中使用HSQL只是证明你的代码对HSQL有效,这与实际不同数据库。这意味着你可以得到误报,反之亦然。使用模拟API或更好的方法可以实现同样的目的,保存数据库测试,以便与真实数据库一起使用。[/ p>

We're using hdsqldb in memory to run junit tests which operate against a database. The db is setup before running each test via a spring configuration. All works fine. Now when a tests fails it can be convinient to be able to inspect the values in the in memory database. Is this possible? If so how? Our url is:

jdbc.url=jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true

The database is destroyed after each tests. But when the debugger is running the database should also still be alive. I've tried connecting with the sqldb databaseManager. That works, but I don't see any tables or data. Any help is highly appreciated!

解决方案

HSQL is in memory, so when you say that you're connecting with SQLDB Database Manager, you're not - you are instead connecting to another database in the memory space of the SQLDB Database Manager, not the one in the memory space of the unit test. This is why the database in the SQLDB Database Manager is empty.

You can run HSQL as a server using org.hsqldb.Server as described here.

Although the org.hsqldb.Server class is typically used to start-up a seperate process, you could instantiate and configure it in your unit test, which should allow a remote process to connect and query the database.

Alternatively, you'll have to write some sort of dump functionality that is called from within your unit test as need be.

As an aside, using HSQL in unit tests is just proving your code works against HSQL, which is different to the actual database. This means you can get false positives and vice versa. The same thing can be achieved with a mocking API or better, save the database testing for some decent integration tests that works with the real database.

这篇关于在调试时检查内存hsqldb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆