伪造的HTTP服务器用于测试目的 [英] Fake http server for testing purpose

查看:180
本文介绍了伪造的HTTP服务器用于测试目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到IP摄像机的应用程序,该应用程序执行HTTP请求以获取图像和M-JPEG.现在还可以,因为我将相机放在开发室中.但是再过几周,该凸轮就会停产(它们是非常昂贵的凸轮),因此我将不再需要它们来测试和调试我的应用程序.

I have an application that connect to an IP camera and that do HTTP request to get image and M-JPEG. For now it's ok because I have the camera in the developpement room. But in a few weeks, the cam will be out in production (they are very expensive cam) so I will not have them for testing and debugging my app.

我想知道的是模拟"这些凸轮的最佳方法是什么?目前,我的应用程序正在使用2个摄像头,假设它们位于 http://192.168.88.1 http://192.168.88.2 .我想到了:

What I want to know is what would be the best way to "mock" these cams? For now, my application is using 2 cams, let's say they are on http://192.168.88.1 and http://192.168.88.2. I have think of this:

  1. 在我的应用程序中,我可以封装执行以下操作的函数: 在中的类中可以进行真正的http请求的http调用 在调试时释放并伪造.不利的一面是它会 不会重现诸如超时和网络之类的真实事物 交通.
  2. 也许我可以在某处放置一个IP cam模拟器 网络和使用?
  3. 也许创建一个真实的http请求到我将拥有的真实服务器 计划返回假图片?如果是这样,该如何进行?
  1. In my application, I could encapsulate the functions that do the http calls in a class that could do real http request when in release and fake when in debug. The bad side of this is that it will not reproduce real thing like occasional timeout and network traffic.
  2. Maybe there is a ip cam simulator somewhere that I can put on my network and use?
  3. Maybe create real http request to a real server that I will have programmed to return fake picture? If so, how to procede?

就像您看到的那样,我有想法,但我不确定什么是最好的,以及外面的人在做什么.考虑到您的回答,请考虑在相机不在时我可以将其用于单元测试和正常调试.

Like you see, I have ideas but I'm not sure what's the best and what people out there are doing. With your answers, take in consideration that I might use it for unit testing as well as normal debugging while the camera is away.

谢谢!

推荐答案

Ad. 1:这是进行单元测试时的一种好方法-您的代码不应依赖于外部服务器/设备/文件系统.但是您已经看到这种环境可能过于理想化了.但是,我的目标是将HTTP基础结构代码外部化-这将同时提高您的测试能力和整体体系结构.

Ad. 1: This is a good approach when unit testing - your code should not depend on external servers/devices/file systems. But you already see that this environment might be too idealized. However I would aim to externalize HTTP infrastructure code - this will both improve your testing capabilities and overall architecture.

广告. 2:从未听说过,对不起.

Ad. 2: Never heard of such, sorry.

广告. 3:我认为这是最可行的解决方案.如果您曾经使用过servlet,只需抓住Tomcat或Jetty并编写一个即可.然后在localhost:8080/war_name/servlet_name下连接到servlet,并从中返回所需的内容. 此处是一个简单的示例.

Ad. 3: I think this is the most feasible solution. If you've ever worked with servlets, just grab Tomcat or Jetty and write one. Then connect to your servlet under localhost:8080/war_name/servlet_name and return whatever you want from it. Here is a dead simple example.

如果您从未听说过Java servlet和servlet容器-仍然值得学习.但是启动内置在Sun JDK中的HTTP服务器可能更快,请参见

If you've never heard about Java servlets and servlet containers - it's still worth to learn about them. But it might be faster to start an HTTP server built into the Sun JDK, see HttpServer API and an example.

这篇关于伪造的HTTP服务器用于测试目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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