Ubuntu上使用autotest做Rails项目的自动测试 - autotest安装和测试

本文介绍如何在Ruby项目中配置自动化测试环境,包括安装ZenTest、redgreen等工具,以及使用libnotify-bin在Ubuntu环境下实现测试结果通知。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Automate Everything: Ruby, Linux and other hints, tips and tricks.

Gnome and Autospec Notifications

autospec notification XFCE/Gnome

注:不需要安装autotest (参考Ruby on Rails 3 Tutorial: 3.2.1 Testing tools),好像是ZenTest里面有autotest了。

安装 ZenTest gem
$ sudo gem install ZenTest
$ sudo gem install redgreen


然后安装libnotify-bin package

$ sudo apt-get install libnotify-bin

在Home目录创建文件 ~/.autotest 内容如下

和原文Automate Everything 唯一不同的地方是要掉redgreen那一行。

#!/bin/ruby # remove this line on Unbuntu 11 : require 'redgreen' require 'autotest/timestamp' module Autotest::GnomeNotify def self.notify title, msg, img system "notify-send '#{title}' '#{msg}' -i #{img} -t 3000" end Autotest.add_hook :ran_command do |at| image_root = "~/.autotest_images" results = [at.results].flatten.join("\n") results.gsub!(/\\e\[\d+m/,'') output = results.slice(/(\d+)\sexamples?,\s(\d+)\sfailures?(,\s(\d+)\spending?|)/) full_sentence, green, failures, garbage, pending = $~.to_a.map(&:to_i) if output if failures > 0 notify "FAIL", "#{output}", "#{image_root}/fail.png" elsif pending > 0 notify "Pending", "#{output}", "#{image_root}/pending.png" else notify "Pass", "#{output}", "#{image_root}/pass.png" end end end end



下载红绿图片到目录~/.autotest_images/.

autotest_images.zip


在Ubuntu X Windows Gnome窗口里面,按CTL + ALT打开一个Terminal窗口,进入你的Rails项目目录,执行autotest,会自动反复测试你的项目,并弹出如上面的X Windows窗口提示你有多少个测试Pass了,多少个测试Failed。


参考:

Rails项目配置rspec: Ruby on Rails 3 Tutorial: 3.2.1 Testing tools

安装配置:Automate Everything

安装配置:http://jetpackweb.com/blog/2009/09/01/autotest-notifications-on-ubuntu-using-lib-notify/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值