自动化命令行应用程序的集成测试
我有一组命令行应用程序,我想自动化其测试。这是为了测试 IaaS 云设置,因此测试将调用启动新的虚拟机实例(例如 euca-run-instances),然后确保它们可以通过 ssh 登录,甚至在远程计算机上运行一些简单的应用程序。
是否有任何框架旨在进行此类测试?我知道有一些框架可以使运行单元测试变得更容易,并且我知道诸如 (p)expect 之类的东西可以与 ssh 之类的东西进行交互,但我不知道有哪些工具存在于这两个世界的交汇处。
I have a set of command-line applications whose tests I'd like to automate. This is for testing an IaaS cloud setup, so the tests will invoke launching new virtual machine instances (e.g. euca-run-instances) and then making sure they can be logged into via ssh, and even running some simple apps on the remote machine.
Are there any frameworks out there that are designed to do this sort of testing? I know there are frameworks to make it easier to run unit tests, and I know of things like (p)expect to interact with things like ssh, but I'm not aware of tools that live in the intersection of these two worlds.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要调用的所有内容都是面向命令行的吗? bash 就是最好的选择。恐怕没有哪个库能让它比现在更通用。
您甚至可以进行远程测试:
这意味着您可以编写脚本,将其上传到服务器上,远程执行它并使用其退出代码来确定成功(0)或失败(1)。
当然,这并不能解决你的所有问题。确切的测试策略取决于您的情况。分割你的工作,让你的生活更轻松。
看一下 shunit,省去编写自己的单元测试框架的麻烦。但我无法真正扩展 Shunt。我在编写自己的工具后发现了它。
Everything you need to invoke is command line oriented? Look no further than bash. I am afraid there is no library that will make it more general than it is already.
You can even do remote testing:
That means you can write a script, upload it on the server, execute it remotely and use its exit code to determine success (0) or failure (1).
Of course that does not solve all your problem. The exact test strategy depends on your situation. Split your work to make your life easier.
Have a look at shunit and save yourself the trouble to write your own unit testing framework. I can't really expand on shunit though. I discovered it after writing my own tool.
Cli-unit 测试给定 cli 使用情况和测试文件位于 markdown 中,因此您可以将它们作为文档包含在内(例如,在您的自述文件中),
例如 README.md
然后运行它:(
阅读有关 cli-unit 此处)
Cli-unit tests for expected output given a cli usage and the test files are in markdown, so you can include them as documentation (e.g. in your readme file)
E.g. README.md
Then run it:
(read more about cli-unit here)
我已经使用 pexpect 和 pyhton 的 unittest 成功测试了 LDAP 系统与客户端服务器的集成。
我们围绕 pexpect 的子 pxssh 编写了一个包装类,它明确针对 ssh 处理。我们在 pxssh 类中编写了函数,它不仅可以捕获输出,还可以返回 $? 的值。命令结束后。
当我们转向单元测试时,这给了我们灵活性。然后可以编写测试,以便我们可以测试输出标准甚至返回值。
我们能够进行单元测试:
作为这项工作的后果,我们调整了 pxssh 类以重新分配 1000 个 Linux 主机的 IP/解析器,这使得工作量很大更方便我们的建筑搬迁。很抱歉,我无法分享更多代码细节,因为工作拥有它(尽管我希望让他们发布它)
I've had a bit of success testing integration of our LDAP system into client servers using pexpect and pyhton's unittest.
We wrote a wrapper class around pexepect's child pxssh, which is explicitly geared around ssh handeling. We wrote functions into the pxssh class that could not only trap the output, but would also return the value of $? after the command ended.
This gave us flexability when we moved to unittest. The tests where then able to be written so that we could test for a output criteria or even against return values.
We where able to unit test:
as a fallout to this work, we adapted the pxssh class to re-ip/resolver over 1000 linux hosts, which made the effort much easier for our building move. I am sorry I cant share more specifics of code as work owns it (although I'm hoping to get them to release it)
Cram 似乎有这个功能。
Cram seems to have this functionality.
这是我的提示:
您可以使用中央主机并使用 ssh 密钥文件授权运行“ssh user@host cmd”
因此,您可以更轻松地控制许多主机。
here is my tips:
you may use a central host and run "ssh user@host cmd" with ssh key file authorize
Thus, you can control your many hosts much more easily.