问题标签 [dbunit]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
3552 浏览

java - integration testing with JPA and Spring

I have a Spring/JPA web application that I would like to write some tests for. Ideally I would like to be able to:

  • create the test DB schema (from the JPA annotated classes) once before the tests are run
  • run each test method in it's own transaction which is rolled back when the test completes
  • specify the (DbUnit) dataset to be loaded for each test either at the per-class or per-method level. The test data should be loaded after the transaction has started so that the test data will also be rolled back when the test completes
  • inject Spring beans into the test class

I'm aware that Spring provides classes which can provide the transactional behaviour I'm seeking. Ideally, the final solution will look something like this

Obviously the parent class and the @TestData are fictitious, is there something available that provides the functionality I'm looking for?

This leaves the question of how to create the test DB schema. Ideally, this would happen once before all the tests are run (by Maven). Can someone suggest how I might achieve this? I imagine it involves using something to convert the JPA annotations to DDL, then something else to load that into the test database schema.

Thanks!

0 投票
1 回答
495 浏览

java - 如何为 JUnit 测试组织数据环境?

我正在创建一个数据密集型 Java EE Web 应用程序,它将其持久数据保存在关系数据库中。现在我想要一些 JUnit 测试来验证某些“数据环境”中的应用程序行为。一些对象应该在测试之前创建并在测试完成时销毁。测试应该能够控制它们的数据设置配置。典型的情况,嗯?现在我的问题是:

  • 使用什么工具呢?DBUnit看起来相当陈旧,并且不是面向 JUnit-4 的。
  • 在哪里放置以及如何命名对象创建者?
  • 如何将配置详细信息传递给他们?Java调用参数?XML 配置?
  • 为了方便起见,我不应该使用ExternalResource JUnit 规则吗?

我很想知道什么是最佳实践。你怎么解决这个问题?

0 投票
0 回答
430 浏览

java - 使用 dbunit 预填充 varbinary 十六进制值

I have a situation where I'm using a MySQL db, with a varbinary column which holds hexadecimal byte data. I'm testing my application with dbunit, and I'd like to be able to pre-populate this column in my flat XML file, but I don't know how to encode a hex value that dbunit will understand. Any help would be great!

0 投票
3 回答
1588 浏览

java - java中的DB后端webapp测试[需要工具]

我想为我的 java web 应用程序创建一个测试套件。它是一个具有 JDBC 连接性的 JSP 应用程序。我的要求如下,

1 - 我应该能够通过我的模型测试我的数据库逻辑(查询等)。

2 - 如果我也可以测试我的 .jsp 页面,那就太好了(如果可能的话)

在做了一些研究之后,我发现 DBUnit 非常适合数据库后端系统测试,但不幸的是我找不到任何好的资源作为入门

你们对我拥有的测试选项有什么看法?如果您也可以发布一些指向资源/示例的链接,那就太好了

编辑:

我遇到了模拟对象(如 JMock ..),想知道我可以用它作为 DBUnit 的替代品吗?

提前致谢

干杯

同龄人

0 投票
1 回答
1237 浏览

oracle - DbUnit HSQLDB - 无效的模式名称:C

当使用以下查询运行测试时,HSQLDB 将表别名误认为是模式。

有谁之前经历过这个吗?如果“是”,那么解决方法是什么?

请注意,如果我更改FROM country_ml as cFROM country_ml as bob,则错误消息会相应更改为invalid schema name: BOB

0 投票
2 回答
2886 浏览

java - DBunit 和数据集列

我想尝试使用 DBUnit 进行单元测试,但我的数据集有问题。

这是我的持久性对象:

还有我的数据集:

我的问题是名称列,我收到此错误:

我不明白为什么 dbunit 搜索列“名称”而我的列是“名称”。

谢谢你的帮助。

0 投票
4 回答
6850 浏览

java - Unitils/DBunit 和数据库测试

我想尝试使用 DBUnit 进行单元测试,但我的数据集有问题。

这是我的持久性对象:

还有我的数据集:

我的问题是名称列,我收到此错误:

我不明白为什么 dbunit 搜索列“名称”而我的列是“名称”。

谢谢你的帮助。

0 投票
1 回答
1298 浏览

hsqldb - 使用 DBUnit 将 HSQLDB 导出到 XML 会导致空指针错误

我正在尝试使用 DBUnit 将我的数据库 HSQLDB 的全部内容导出到 XML,并且我遇到了我无法理解的空指针错误。我正在关注常见问题解答中的示例:

p>

空指针错误发生在最后一行。conn 和 DATABASE_PATH 不为空,因为它们都经过检查并稍后在程序中使用而没有问题(使用 OpenCSV 将数据库导出为 CSV,它可以完美地完全按预期工作)。

堆栈跟踪如下:

p>

我用谷歌搜索,在导出过程中找不到与此类错误相关的任何内容。我对 SQL 或 JDBC 没有那么丰富的经验,所以我希望堆栈跟踪中有足够的信息,以便更有知识的人告诉我出了什么问题。如果有一些其他库可以更好地满足我的需求,那么我可以毫无问题地切换......我现在唯一需要的是使用 XML 导出/导入,所以我没有将 DBUnit 用于其他任何事情。无论如何,如果有人能告诉我出了什么问题,或者我是否应该使用其他东西,我将不胜感激。

0 投票
1 回答
2167 浏览

java - Unitils / DBunit / Oracle - 如何在 oracle 视图中插入数据集?

这似乎是一个简单的问题。我在 spring 应用程序中有一些 unitils 测试。数据库包含一些 oracle 视图,我只想将数据集插入这些视图。我知道可以将选项设置为 DBunit(表类型属性)。但我找不到单位。

是否有一些用于将数据集插入视图的 unitils 属性?

谢谢你的帮助

0 投票
3 回答
8369 浏览

dbunit - DBUnit 中的日志输出

我觉得这是我很容易弄清楚的事情,但是我很难找到有关如何更改 DBUnit 日志级别的信息。谁能帮我解决这个问题?