简体   繁体   English

SSH 的单元测试还是集成测试?

[英]Unit or Integration testing for SSH?

I am currently using phpseclib to allow me to connect to SSH.我目前正在使用phpseclib来允许我连接到 SSH。

I will be using phpseclib quite a lot to connect to many servers via SSH and execute some commands.我将大量使用 phpseclib 通过 SSH 连接到许多服务器并执行一些命令。

I have created a SecureShell class (like a adaptor pattern) with a few methods such as login() and exec() .我创建了一个SecureShell类(如适配器模式),其中包含一些方法,例如login()exec() These method will execute the server via phpseclib object.这些方法将通过 phpseclib 对象执行服务器。

I am trying to work out what is a good way to test the login and execute a command a server - should I mock it SecureShell class or do Integration testing which mean I need a separate real testing server (not development local server?)我正在尝试找出测试登录并在服务器上执行命令的好方法 - 我应该模拟它SecureShell类还是进行集成测试,这意味着我需要一个单独的真实测试服务器(而不是开发本地服务器?)

Ultimately, you would want both.最终,你会想要两者。

You would want unit tests with a mocked SecureShell so that you know that your code is asking to run the correct commands.您需要使用SecureShell单元测试,以便您知道您的代码要求运行正确的命令。 You would also want to have some sort of integration tests that you can verify that your connection is setup correctly and will work in production.您还需要进行某种集成测试,以验证您的连接是否正确设置并且可以在生产中使用。

Tests are so that you are confident that there are no problems with your code and that everything will work correctly.测试是为了让您确信您的代码没有问题并且一切正常。 So you want whatever tests will provide you with that confidence.所以你想要任何能让你充满信心的测试。

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

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