在 Rails 中对暂存/生产环境进行冒烟测试的最佳方法是什么?
首先,设置...
我目前正在 Mac OS X 上使用 Ruby 1.8.7 MRI 开发 Rails 3 应用程序,针对 MySQL 数据库运行测试和本地开发。我有 3 个“其他”非本地环境,我们在公司中为每个应用程序使用这些环境,称为 dev、tqa 和 prod。它们使用 JRuby (1.8.7) 在 Tomcat 中运行,并以 Oracle 作为后端。
正如您所看到的,环境有很大不同,我们在部署到本地不存在的 Oracle/JRuby 环境时遇到了一些错误(例如 Oracle 中的日期处理和指定默认模式)。
我喜欢在本地运行 Cucumber/Webrat/Capybara 之类的东西来访问应用程序中公开的每个 URL,以确保基本功能正常工作(即冒烟测试)。理想情况下,它会命中每个 url,并且会执行一些简单的操作,例如在表单中输入数据和单击按钮等。
理想情况下,当我部署到 dev/tqa 时,我会运行类似的操作,除了指向已部署的应用程序而不是本地应用程序。 Cucumber 似乎针对本地运行的应用程序进行了优化,并与 Rails 很好地集成,但无法针对所有意图的“外部”应用程序运行(或者至少我找不到实际有效的简单方法)。
另外,当我部署到产品时,我希望运行一套类似的冒烟测试,但它不会改变当前生产数据库的状态(即,只会获取 URL)。
我想可以使用像 Selenium 这样的东西,但我真的很想运行一个 rake 任务并返回结果,就像我对 Cucumber 所做的那样。
有没有任何 Rails/Ruby 方法可以做到这一点,或者其他人只是使用 wget 或 Selenium 推出自己的解决方案?
此处提出了类似的问题:自动对应用程序中的所有网页进行烟雾测试,部署后
不过,我不确定这个问题是否正是我所想的。
First, the setup...
I am currently developing a Rails 3 application on Mac OS X using Ruby 1.8.7 MRI, running tests and local dev against a MySQL database. I have 3 "other" non-local environments that we use at my company for every application called dev, tqa, and prod. These run in Tomcat using JRuby (1.8.7) with Oracle as the backend.
As you can see, the environments are quite different, and we've run into some bugs on deployment to an Oracle/JRuby environment that don't exist locally (like date handling and specifying default schemas in Oracle).
I love running something like Cucumber/Webrat/Capybara locally to hit every URL exposed in the app to make sure the basic stuff is working (ie; a smoke test). Ideally, it hits every url, and would do some simple things like entering data in forms and clicking on buttons, etc.
Ideally, when I deploy to dev/tqa, I would run something similar, except pointed at the deployed app instead of the local application. Cucumber seems optimized to hit a locally running application and integrates well with Rails, but cannot run against what is for all intents an "external" application (or at least I can't find an easy way that actually works).
Also, when I deploy to prod I'd like a similar suite of smoke tests to run, except it would not change the state of the current production database (ie, would just GET URLs).
Something like Selenium could be used, I guess, but I'd really like to just run a rake task and get back the results like I do with Cucumber.
Is there any Rails/Ruby way to go about doing this, or does everyone else just roll their own solution using wget or Selenium?
A similar question was asked here: Automatically smoke test all webpages in application, after deployment
I'm not sure that the question is exactly what I have in mind, though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以使用 Cucumber 和 Capybara 编写冒烟测试,并针对远程服务器运行它们。我已经做到了并且有效。我还在一些项目上做过
curl
/wget
等,但是 Cucumber+Capybara 允许您与页面交互(甚至是使用 Javascript 的页面),而不仅仅是抓取他们。Rack::Test
驱动不支持远程请求;它的 Javascript 驱动程序可以。无论您是否确实需要 Javascript 在您正在测试的页面上工作,您都需要使用 Javascript 驱动程序。根据驱动程序文档将 Capybara 配置为使用 Javascript 驱动程序,并标记您的测试@javascript
。 (我推荐poltergeist/PhantomJS驱动程序;它比Selenium更快,比capybara-webkit提供更好的错误,并且易于设置。)额外的好处:你可以在测试中做需要Javascript的事情,然后你会很高兴-测试整个堆栈,包括 Javascript。Capybara.app_host = "http://your-server.yourco.com"
Capybara.run_server = false
(不是必需的,但运行本地服务器没有意义 如果您的测试Yes, you can write smoke tests with Cucumber and Capybara and run them against remote servers. I've done it and it works. I've also done
curl
/wget
and the like on some projects, but Cucumber+Capybara allows you to interact with pages (even ones that use Javascript), not just scrape them.Rack::Test
driver doesn't support remote requests; its Javascript drivers do. Whether or not you actually need Javascript to work on the pages you're testing, you'll need to use a Javascript driver. Configure Capybara to use a Javascript driver per the driver's docs and tag your tests@javascript
. (I recommend the poltergeist/PhantomJS driver; it's faster than Selenium, gives better errors than capybara-webkit, and is easy to set up.) Bonus: you can do things in your tests that need Javascript, and you'll be smoke-testing your entire stack including Javascript.Capybara.app_host = "http://your-server.yourco.com"
Capybara.run_server = false
(not required, but there's no point running a local server that you won't use)简单地攻击应用程序以查看其是否崩溃的一种方法是从生产 Web 服务器日志文件中获取 GET 请求列表,并将这些请求输入到诸如
curl
或wget< 之类的程序中。 /code> 将尽快获取它们。
这是一个简单的示例:
给定一个标准 Web 日志文件,其中包含与
"GET /... HTTP/1.1"
匹配的行,您可以轻松提取路径,但有必要提供基本 URI:这将列出输出在该日志文件中找到的所有 URL。您可以将其通过管道传输到
wget
来获取数据:如果您破坏了任何内容,您将开始在应用程序中收到错误,并且通过适当的通知系统,您将能够捕获这些错误并进行跟踪他们下来了。
One way to simply beat on your application to see if it blows up is to grab a list of GET requests from your production web server log file and feed those into a program like
curl
orwget
that will fetch them all as quickly as possible.Here's a simple example:
Given a standard web log file with lines matching
"GET /... HTTP/1.1"
you can easily extract the paths, but it's necessary to provide the base URI:This will list out all the URLs found within that log file. You can pipe this to
wget
for fetching purposes:If you've broken anything, you'll start getting errors in your application, and with a proper notification system you'll be able to catch these and track them down.