是的,Ruby 非常适合系统或应用程序级别的测试。
我会推荐黄瓜。Cucumber 是一个 Ruby 应用程序,它允许您定义特定于您的环境的外部 DSL(域特定语言),然后使用该 DSL 来编写和运行测试。
这是 Cucumber 测试示例(来自 Cucumber 主页):
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
那是用您定义的迷你语言编写的。这些“步骤定义”在 Ruby 中,使用 Cucumber 的内部 DSL:
Given /I have entered (.*) into the calculator/ do |n|
calculator = calculator.new
calculator.push(n.to_i)
end
这些步骤定义将您的自定义外部 DSL 与被测代码或系统联系起来。此示例测试一个简单的 Ruby 类,但 Cucumber 非常适合库或应用程序的集成测试。
保持干燥不是问题。步骤定义可以调用其他步骤定义,并且由于它们是用 Ruby 编写的,因此您可以轻松地将共享代码放入模块或类中以供您的步骤定义使用。
剩下要回答的是 Ruby 及其可用库是否具有驱动测试环境所需的功能。Ruby 是一种很好的“粘合”语言,能够轻松运行其他程序。它还有一组相当不错的库(称为“Ruby gems”)可用,包括几个可以做肥皂的库(例如savon)。库可用于处理 XML 并与各种协议(HTTP、FTP 等)进行交互。