集成测试谁下载文件 [英] Integration tests who download files

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

问题描述

我正在开发一个网络应用程序,它可以完成一些工作,将数据打包到一个文件中,然后将文件还给您(Content-Type: application/force-download).现在,我正在实施一些集成测试,在其中要求数据,Web应用程序将文件退还给我.测试下载预期数据时,Web应用程序的行为正确.我读了,我发现它很有启发性,但是当您建立您要下载的文件?

I am developing a web app who does some work, pack the data in a file and gives you back that file (Content-Type: application/force-download). Right now I am implementing some integration tests, where I ask for data and web app gives me back the file. Web app behaves correctly when test downloads expected data. I read this and I found it very inspiring but is that response valid when you build the file you want to download?

推荐答案

您可以采用几种方法.从好到坏(YMMV):

There are several approaches you can take. In order from best to worst (YMMV):

从语义上检查输出.例如,对于JSON,请检查其是否可以解析,并提供预期的键和值.如果是图片,请检查图片是否可以解析并具有正确的格式.

Check the output semantically. For example, in case of JSON, check that it can be parsed, and expected keys and values are present. In case of an image, check that it can be parsed and has the right format.

专业人士:您只测试您真正关心的内容.测试失败可能指向一个特定的问题.

Pro: You're only testing what you actually care about. Test failures can point at a specific problem.

骗局:需要做更多的工作.

Con: Takes more work.

直接逐字节比较文件.黄金大师"方法.如果该文件大于几行,或者它是一个二进制文件,那么我会将其放在磁盘上,并进行集成测试.这也使您可以更轻松地在外部程序中查看/编辑它.

Compare the file directly, byte by byte. The "golden master" approach. If the file is bigger that a few lines, or it's a binary file, I would put it on disk and have the integration test load it. This will also let you view/edit it in an external program more easily.

专业人士:很容易看到预期的文件.

Pro: It's easy to see what the expected file looks like.

缺点:在不相关的更改的情况下可能会变脆.例如,JSON对象中的键顺序无关紧要.更糟糕的是,如果要生成PNG图像,则创建时间可能会嵌入到文件中,因此每次测试都会失败.

Con: Can be brittle in case of irrelevant changes. For example, the order of keys in a JSON object should not matter. Worse, if you're generating a PNG image, the time of creation could be embedded into the file so your test would fail every time.

比较文件哈希.我认为这是万不得已的方法.

Compare the file hash. I would view this as a last resort.

专业人士:您不需要在集成测试中存储整个文件,这只有在文件很大的情况下才可以.

Pro: You don't need to store the entire file in your integration test, which is only nice if it's really big.

缺点:测试失败不会告诉您任何信息.即使是集成测试中嵌入的哈希也无法告诉您任何信息.这只是一个变更检测器"测试.

Con: A test failure tells you nothing. Even the hash embedded in your integration test tells you nothing. This is just a "change detector" test.

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

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