简体   繁体   English

假FTP服务器

[英]Fake FTP server

I'm writing a C++ class that performs some operations as an FTP client. 我正在编写一个C ++类,它作为FTP客户端执行一些操作。 I'd like to set up some tests for it so I would need to use a fake FTP server. 我想为它设置一些测试,所以我需要使用假的FTP服务器。

I've been searching for one and I think I could write some scripts in Python and use pyftpdlib . 我一直在寻找一个,我想我可以用Python编写一些脚本并使用pyftpdlib But I guess there will be some drawbacks as for setting up and tearing down the server after each test. 但我想在每次测试后设置和拆除服务器都会有一些缺点。

Any suggestions on how to easily run a fake FTP server for automatic testing in C++ are welcome. 有关如何轻松运行假FTP服务器以便在C ++中自动测试的任何建议都是值得欢迎的。

EDIT: 编辑:

I've broadened out my search a little bit and found MockFtpServer , which is exactly what I was looking for, though written in C++ instead of Java. 我已经扩展了我的搜索并找到了MockFtpServer ,这正是我想要的,尽管是用C ++而不是Java编写的。

You should design your code for testability, in this case the FTP server is a external resource. 您应该设计可测试性代码,在这种情况下,FTP服务器是外部资源。 Define an adapter between your program and the ftp server. 在程序和ftp服务器之间定义适配器。 In test you can put a test adapter to fake the FTP response. 在测试中,您可以放置​​一个测试适配器来伪造FTP响应。 Now you can also fake different behaviors for the ftp server. 现在您还可以伪造ftp服务器的不同行为。

If you're talking about Unit Testing, then @peer's answer is correct. 如果您正在谈论单元测试,那么@ peer的答案是正确的。 You should mock up the FTP connection, because ideally your unit tests are running as part of each build and they shouldn't depend on things that are outside of the client's package. 您应该模拟FTP连接,因为理想情况下,您的单元测试作为每个构建的一部分运行,并且它们不应该依赖于客户端软件包之外的东西。

OTOH, if you're talking about System/Integration Testing, then you should have a working clone of the supported production environment(s), including an FTP server. OTOH,如果你在谈论系统/集成测试,那么你应该有一个支持的生产环境的工作克隆,包括一个FTP服务器。 I'm not sure why you'd want a 'fake' FTP server for your System/Integration Testing though. 我不知道你为什么要为你的系统/集成测试想要一个'假的'FTP服务器。 Probably best to go with an FTP server that your clients would actually be using. 可能最好使用客户实际使用的FTP服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM