DbUnit 和二进制数据

发布于 2024-08-19 00:53:10 字数 198 浏览 9 评论 0原文

我使用 DbUnit 对 DAO 对象进行单元测试。到目前为止效果很好。

我有一个问题,我有字段 ob 类型 byte[] ,它以 BLOB 形式存储在数据库中。该列不为空。如何在 DbUnit 使用的 XML 数据集文件中指定此列的值?该值可以不花哨,5 个字节就足够了。我想避免为此创建额外的二进制文件。

有什么建议吗?

I use DbUnit for unit-testing of my DAO objects. It works great so far.

I have a problem, I have field ob type byte[] which is stored as BLOB in the database. The column is not-null. How can I specify the value for this column in the XML dataset file, that DbUnit uses? The value can be nothing fancy, 5 bytes will be enough. I would like to avoid necessity to create extra binary files just for this.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

方觉久 2024-08-26 00:53:10

毕竟我是这样解决的:

XML 数据集文件:

<?xml version="1.0" encoding="UTF-8"?>
<dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <!-- image_content is string '12345' Base64 encoded -->
    <IMAGE IMAGE_ID="1" IMAGE_CONTENT="MTIzNDU="/>
</dataset>

DbUnit 内置了对 Base64 编码数据的支持,它可以正确转换为字节数组。

测试用例代码:

assertEquals("12345".getBytes(), image.getContent());

After all I solved it like that:

XML dataset file:

<?xml version="1.0" encoding="UTF-8"?>
<dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <!-- image_content is string '12345' Base64 encoded -->
    <IMAGE IMAGE_ID="1" IMAGE_CONTENT="MTIzNDU="/>
</dataset>

DbUnit has built-in support for Base64 encoded data, it transformes correctly into byte array.

Test case code:

assertEquals("12345".getBytes(), image.getContent());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文