Chinaunix首页 | 论坛 | 博客
  • 博客访问: 556755
  • 博文数量: 107
  • 博客积分: 3079
  • 博客等级: 少校
  • 技术积分: 1306
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-08 00:03
个人简介

emmoblin.github.com

文章分类

全部博文(107)

文章存档

2012年(8)

2011年(15)

2010年(49)

2009年(9)

2008年(26)

分类: LINUX

2010-08-02 22:35:26

直接上代码,看看到底用脚本写测试用例到底有多简单。


lsystem = function (arg)
    print("cmd:\e\[31m"..arg.."\e\[0m")
    local date = io.popen(arg, r)
    local str = date:read"*a"
    date:close()
    return str
end

--测试mac地址的显示是否正确

function test_ipshow()
    date = lsystem("ip addr show eth1")
    assert_match("00:0a:e4:36:06:24",date)
end


简单到无法再简单的程序,只需要两句话,
第一句是执行命令。
第二句是判断返回内容是否正确。

优势一:
如果要使用Cunit进行同样的测试,当然也基本上也都是这几行语句,但是最麻烦的就是需要对内存进行管理。
优势二:
同时使用c语言的字符串匹配没有脚本语言强大,至少支持正则匹配。
优势三:
不需要编译,直接修改,解释执行。


阅读(2258) | 评论(0) | 转发(0) |
0

上一篇:emacs mingus

下一篇:emacs todo-mode

给主人留下些什么吧!~~