自动化命令行应用程序的集成测试

发布于 2024-11-29 09:27:03 字数 235 浏览 1 评论 0原文

我有一组命令行应用程序,我想自动化其测试。这是为了测试 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

风追烟花雨 2024-12-06 09:27:03

您需要调用的所有内容都是面向命令行的吗? bash 就是最好的选择。恐怕没有哪个库能让它比现在更通用。

您甚至可以进行远程测试:

$ ssh user@server /bin/false ; echo $?
1

$ ssh user@server /bin/true ; echo $?
0

这意味着您可以编写脚本,将其上传到服务器上,远程执行它并使用其退出代码来确定成功(0)或失败(1)。

当然,这并不能解决你的所有问题。确切的测试策略取决于您的情况。分割你的工作,让你的生活更轻松。

  • vm 设置
  • vm 测试
  • vm 部署(此处添加服务器特定的内容)
  • 部署 vm 测试
  • 部署 vm 清理(删除测试内容)

看一下 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:

$ ssh user@server /bin/false ; echo $?
1

$ ssh user@server /bin/true ; echo $?
0

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.

  • vm setup
  • vm testing
  • vm deployment (server specific stuff added here)
  • deployed vm testing
  • deployed vm cleanup (remove testing stuff)

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.

你对谁都笑 2024-12-06 09:27:03

Cli-unit 测试给定 cli 使用情况和测试文件位于 markdown 中,因此您可以将它们作为文档包含在内(例如,在您的自述文件中),

例如 README.md

### test: echo foo should output "foo"
#### when: 
    echo foo
#### then: 
    foo

然后运行它:(

cli-unitw.sh README.md 
Pass (1/1 tests successful)

阅读有关 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

### test: echo foo should output "foo"
#### when: 
    echo foo
#### then: 
    foo

Then run it:

cli-unitw.sh README.md 
Pass (1/1 tests successful)

(read more about cli-unit here)

卖梦商人 2024-12-06 09:27:03

我已经使用 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:

  • successful logged in
  • expected to fail login
  • expected folders
  • expected files
  • presence of login banners

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)

浪荡不羁 2024-12-06 09:27:03

Cram 似乎有这个功能。

Cram seems to have this functionality.

笑叹一世浮沉 2024-12-06 09:27:03

这是我的提示:
您可以使用中央主机并使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文