DbUnit 和二进制数据 [英] DbUnit and binary data

查看:42
本文介绍了DbUnit 和二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

有什么建议吗?

解决方案

毕竟我是这样解决的:

XML 数据集文件:

<前><?xml version="1.0" encoding="UTF-8"?><数据集 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ><!-- image_content 是字符串 '12345' Base64 编码 --><IMAGE IMAGE_ID="1" IMAGE_CONTENT="MTIzNDU="/>

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

测试用例代码:

<前>assertEquals("12345".getBytes(), image.getContent());

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?

解决方案

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());

这篇关于DbUnit 和二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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