简体   繁体   中英

Fake FTP server

I'm writing a C++ class that performs some operations as an FTP client. I'd like to set up some tests for it so I would need to use a fake FTP server.

I've been searching for one and I think I could write some scripts in Python and use 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.

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.

You should design your code for testability, in this case the FTP server is a external resource. Define an adapter between your program and the ftp server. In test you can put a test adapter to fake the FTP response. Now you can also fake different behaviors for the ftp server.

If you're talking about Unit Testing, then @peer's answer is correct. 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.

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. I'm not sure why you'd want a 'fake' FTP server for your System/Integration Testing though. Probably best to go with an FTP server that your clients would actually be using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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