图像下载java的集成测试 [英] Integration test for image download java

查看:92
本文介绍了图像下载java的集成测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写集成测试,以查看是否从网址正确下载了文件。
我不知道如何测试这个,因为我希望在byte []中获取文件,但我不确定我正在比较它的图像。
我想手动下载文件,然后将其转换为字节并将结果粘贴到代码中作为预期值,然后将其与我得到的结果进行比较。
如果你有更好的想法,我会很高兴听到它。

I'm trying to write an integration test to see if a file is downloaded correctly from a url. I'm not sure how to test this because I expect to get the file in byte[] but I not really sure about the image that I'm comparing it to. I thought about downloading the file manually and then convert it to bytes and take the result and paste it in the code as the expected value and than compare it to the result i get. If you have a better idea I would be glad to hear it.

谢谢:)

推荐答案

比较图像的哈希值会很有帮助。

Comparing the images' hash value will be helpful.


  1. 在下载文件之前和之后计算哈希值。

  2. 比较哈希值。如果它们相同,则文件的完整性很好。

您可以使用MD5或SHA-1等哈希算法。如果文件较小MD5是好的。对于大量文件比较,SHA-1将非常有用,因为冲突会更少。

You can use hash algorithms like MD5 or SHA-1. If the files are smaller MD5 is good. For large number of file comparison SHA-1 will be useful since there will be less collisions.

这篇关于图像下载java的集成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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