免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3539 | 回复: 1
打印 上一主题 下一主题

Fitnesse, Fit and Ruby [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-23 14:33 |只看该作者 |倒序浏览
Fitnesse, Fit and Ruby





昨天花了一些时间在这方面上。 Austin问能不能使用Fitnesse,所以试用了一下。

Fitnesse 是一个很优秀的测试工具。acceptance testing。
Fit 同上。

由于官方站点没有给出Ruby 相关的文档,只有Java 和 C#的(貌似),所以我就把安装和运行例子的过程记录了下来,供大家参考:
  1. Due to no documents available for Ruby on "fitnesse" official website, I recorded my steps of installation and running its examples:

  2. (references:   
  3. NOTE: guides on these 2 sites don't work and are out-of-date!
  4. http://xprogramming.com/articles/rubyfitnesse/
  5. http://blog.coryfoy.com/2005/12/fitnesse-and-ruby-a-basic-tutorial/
  6. )

  7. 1. $sudo gem install fit   
  8. 2. download the fitnesse.jar file  (下载这个文件)
  9. 3. java -jar fitnesse.jar -p 8080
复制代码
现在fitnesse 已经跑起来了。打开 localhost:8080, 发现它就是个wiki.

4. 随便编辑一个页面,末尾加上这句话: (edit anyone page, add this line to the end)
^ArithmeticFixture

5. 保存。刷新。打开这个新页面。 (save & fresh & open this new page)

6. 加入这个内容: (add these line of codes)  


Java代码
  1. 1.!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}   
  2. 2.  
  3. 3.!path "/usr/lib/ruby/gems/1.8/gems/fit-1.2/lib/eg"  
  4. 4.!|eg.ArithmeticFixture|   
  5. 5.|x|y|+|-|*|/|   
  6. 6.|1|1|2|0|1|1|  
  7. !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}

  8. !path "/usr/lib/ruby/gems/1.8/gems/fit-1.2/lib/eg"
  9. !|eg.ArithmeticFixture|
  10. |x|y|+|-|*|/|
  11. |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 就能自动生成单元测试了,但是实现代码乱了。。。 比如:

Java代码
  1. 1.class ArithmeticFixture < Fit::PrimitiveFixture   
  2. 2.  def initialize   
  3. 3.    super  
  4. 4.    @x = @y = 0  
  5. 5.  end   
  6. 6.  def do_rows rows   
  7. 7.    super(rows.more) # skip column heads   
  8. 8.  end   
  9. 9.  def do_cell cell, column_index   
  10. 10.    case column_index   
  11. 11.      when 0 then @x = parse_integer(cell);   
  12. 12.      when 1 then @y = parse_integer(cell);   
  13. 13.      when 2 then check(cell, parse_integer(cell), @x + @y)   
  14. 14.      when 3 then check(cell, parse_integer(cell), @x - @y)   
  15. 15.      when 4 then check(cell, parse_integer(cell), @x * @y)   
  16. 16.      when 5 then check(cell, parse_integer(cell), @x / @y)   
  17. 17.      else ignore(cell)   
  18. 18.    end   
  19. 19.  end  
  20. class ArithmeticFixture < Fit::PrimitiveFixture
  21.   def initialize
  22.     super
  23.     @x = @y = 0
  24.   end
  25.   def do_rows rows
  26.     super(rows.more) # skip column heads
  27.   end
  28.   def do_cell cell, column_index
  29.     case column_index
  30.       when 0 then @x = parse_integer(cell);
  31.       when 1 then @y = parse_integer(cell);
  32.       when 2 then check(cell, parse_integer(cell), @x + @y)
  33.       when 3 then check(cell, parse_integer(cell), @x - @y)
  34.       when 4 then check(cell, parse_integer(cell), @x * @y)
  35.       when 5 then check(cell, parse_integer(cell), @x / @y)
  36.       else ignore(cell)
  37.     end
  38.   end
复制代码
5. 这个是单元测试,而不是粒度比较大的集成测试(integration test, or gui test . )
6. 对于Ruby的支持很烂。很过时。官方文档居然都没有Ruby的例子。
7. 现有的例子用的都是最简单的数据类型: 计算器,除法,开方等等。复杂的就不支持了,例如一个http response对象。  

综上,Fitnesse用来搞个算法的TDD 还行, 要是用来做web app, 还得rspec , test-unit.

最后:不管开发什么,不管用什么工具,只要心里想着“测试驱动”,我们用最基本的test-unit,一样可以写出纯TDD的程序。 :)

论坛徽章:
0
2 [报告]
发表于 2013-05-14 16:42 |只看该作者
每个工具都有优秀的地方,也都有不足之处,关键是使用的是否得当。
我们用fitnesse做了一些自动化测试,我觉得还是比较好用的,可以很好的将测试数据和测试脚本分离。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP