Fitnesse & Fit 和 Ruby。

Fitnesse, Fit and Ruby昨天花了一些时间在这方面上。 Austin问能不能使用Fitnesse,所以试用了一下。Fitnesse 是一个很优秀的测试工具。acceptance testing。Fit 同上。由于官方站点没有给出Ruby 相关的文档,只有Java 和 C#的(貌似),所以我就把安装和运行例子的过程记录了下来,供大家参考:Due to no documents available for Ruby on “fitnesse” official website, I recorded my steps of installation and running its examples: (references: NOTE: guides on these 2 sites don’t work and are out-of-date!http://xprogramming.com/articles/rubyfitnesse/ http://blog.coryfoy.com/2005/12/fitnesse-and-ruby-a-basic-tutorial/) 1. $sudo gem install fit 2. download the fitnesse.jar file (下载这个文件)3. java -jar fitnesse.jar -p 8080现在fitnesse 已经跑起来了。打开 localhost:8080, 发现它就是个wiki. 4. 随便编辑一个页面,末尾加上这句话: (edit anyone page, add this line to the end) ^ArithmeticFixture5. 保存。刷新。打开这个新页面。 (save & fresh & open this new page)6. 加入这个内容: (add these line of codes)

!define COMMAND_PATTERN {/usr/bin/ruby -I %p -I /usr/lib/ruby/gems/1.8/gems/fit-1.2/lib /usr/lib/ruby/gems/1.8/gems/fit-1.2/bin/FitServer.rb}!path "/usr/lib/ruby/gems/1.8/gems/fit-1.2/lib/eg"!|eg.ArithmeticFixture||x|y|+|-|*|/||1|1|2|0|1|1|

7. 保存它。然后修改它的属性,把它变成”Test”,然后测试,就可以看到结果了。(now you can turn it to be a fit test, then run it, you will get the expected result)以下话题对RUBY ON RAILS 展开: 不过让人觉得遗憾的是,fitnesse感觉很一般,除了表格很让人眼前一亮,其他的都不行。比如“不懂编程语言的人也可以写测试”,就是很不现实的东东。 写个 rspec 很难吗?fitnesse 就是wiki + 单元测试。 这里我说的是“单元测试”,而不是集成测试。更不是像Selenium那样的对浏览器进行自动化测试。 比较简单的测试用例: 1 + 1 = 2. 都可以写。非常强悍的地方: 1. 表格(Decision Table)的表现力非常丰富。2. 不必写单元测试(rspec, test-unit)最典型的几个不足:1. 输入函数,输出结果只能是基本的数据类型。例如: 数字,字符。不能是复杂对象2. 不能测试web app. (最关键)3. 不能测试某些方法:生成PDF, 上传下载, 权限控制等等。4. 实现代码必须继承 Fit 自带的class, 有的时候还要实现一些奇怪的方法。 是的,咱用wiki 写个 table 就能自动生成单元测试了,但是实现代码乱了。。。 比如:

class ArithmeticFixture < Fit::PrimitiveFixture  def initialize    super    @x = @y = 0  end  def do_rows rows    super(rows.more) # skip column heads  end  def do_cell cell, column_index    case column_index      when 0 then @x = parse_integer(cell);      when 1 then @y = parse_integer(cell);      when 2 then check(cell, parse_integer(cell), @x + @y)      when 3 then check(cell, parse_integer(cell), @x - @y)      when 4 then check(cell, parse_integer(cell), @x * @y)      when 5 then check(cell, parse_integer(cell), @x / @y)      else ignore(cell)    end  end

5. 这个是单元测试,而不是粒度比较大的集成测试(integration test, or gui test . )6. 对于Ruby的支持很烂。很过时。官方文档居然都没有Ruby的例子。7. 现有的例子用的都是最简单的数据类型: 计算器,除法,开方等等。复杂的就不支持了,例如一个http response对象。 综上,Fitnesse用来搞个算法的TDD 还行, 要是用来做web app, 还得rspec , test-unit. 最后:不管开发什么,不管用什么工具,只要心里想着“测试驱动”,我们用最基本的test-unit,一样可以写出纯TDD的程序。 :)人生就是一场旅行,不在乎目的地,

Fitnesse &amp;amp; Fit 和 Ruby。

相关文章:

你感兴趣的文章:

标签云: