Wordpress themes are available for download at wordpress-related website.

IT mmpower on 20 Sep 2006 07:27 am

canoo web test 快速入门

这是我们实现Agile development重要的一环.

(0) 安装

– download jave runtime (JRE)
– download webtest: http://webtest.canoo.com/webtest/build.zip, 解压到本地目录 <WEBTEST_HOME> (例如, C:\webtest)
– Add <WEBTEST_HOME>\bin to your PATH (控制面板–>系统–>高级–>环境变量)
–cd <WEB_HOME>\doc\samples 运行:
webtest -buildfile installTest.xml

一般来说,运行test cases用这样的语法:
webtest -buildfile <testcasefile>

例如,

webtest -buildfile mytest.xml

(1)test cases目录结构

建立一个目录叫testcases,testcases放到该目录下面

testcases
includes: 包含文件
properties: 存储一些与环境相关或常变化的测试数据
modules:小的可重用的测试模块
UseCases : 对应于use cases的test cases
TestResults: 存放测试结果和报告.

建立一个 web directory 指向TestResults目录. 例如, http://localhost/TestResults/testresult.html 就可以看见测试报告.

(2) 简单例子:

附件这个简单test case是验证海归网登陆的:

把这个文件存为mytest1.xml, (去掉.doc后缀), 放到TestCases目录下,把name="webtest.home" location="E:/canoo" 中location的值改为你的canoo web test的根目录.

然后运行 webtest -buildfile mytest1.xml;运行完毕后到http://localhost/TestResults/results.html看测试报告.

最后一步应该是失败的,因为crazytang的password不对. 要想测试测试成功需要把上面login.ok.password的值改成crazytang的密码.

注:测试报告格式和语言可以通过XSLT定制;回头我们会修改一下现在的报告格式,并且加上email通知功能.

(3) Canoon WebTest 的功能简介

背景: canoo webtest是用java 编写的,我们上述的例子用 ant 执行.(ant本身是一个java build tool, 相当于make,但比make强的多)

它是一个web acceptance工具,而不是一个junit/htmlunit/phpunit之类的unit test工具,也就是说进行黑箱测试. 在用于开发时.需要预先根据
详细需求编写test cases(实际上也是use cases)把期望的web site什么样子有什么功能表达出来.

test cases是xml格式的,一般来说需要手工编写 (如果是对现有网站测试,可以用工具自动把用户手工测试的过程记录下来自动生成test cases,但对于新项目开发来说没有什么用处);

(4)test case编写入门

看看上面的简单例子.
每个<webtest> 元素代表一个 web session,里面包括<config>和<steps>. 前者定义访问的网站属性,后者是一系列测试的步骤,例如采取什么行动(点击button,设置cookie等),或者验证
返回页面(标题,内容,图象, response code等等);每个步骤都有一个相对应的webtest step. webtest当前所有支持的步骤主要见见:

http://webtest.canoo.com/webtest/manual/syntaxCore.html
http://webtest.canoo.com/webtest/manual/syntaxExtension.html

此外还有关于email/pdf/excel等的验证,config等的语法,详见手册: http://webtest.canoo.com/webtest/manual/manualOverview.html

(5) property, 包含文件等:

可以定义类似变量的property, 例如我上面简单例子中引用的${user}, ${login.ok.password}等都是在文件开始定义的properties.详细的propeties用法
见http://webtest.canoo.com/webtest/manual/properties.html

test cases可以由许多可重用的模块组成,这样易于维护减少冗余. 详细请见: http://webtest.canoo.com/webtest/manual/samples.html.

(6) 如果有必要直接在数据库中准备测试数据,(例如测试前需要建立一批用户)可以用与SQLUNIT结合实现:

详见 http://webtest.canoo.com/webtest/manual/sqlunit.html

(7)这里有些用户贡献的工具或测试步骤: http://webtest-community.canoo.com/wiki/space/Contributions+and+Uploads

(8) 我们会设置一个cron job(scheduled task)每夜自动运行所有test cases.

(9) test cases也存入SVN中.

7 Responses to “canoo web test 快速入门”

  1. on 20 Sep 2006 at 7:28 am 1.mmpower said …

    标题:大家试一下; 有问题请跟贴

    这是个初步入门的大概,以后有时间继续整理.

  2. on 20 Sep 2006 at 10:24 am 2.hick said …

    标题::) 俺暂时还没时间去试

    大概搜索了一下,国内能够找到的资料极少 :)

    看上去停不错的,好象比 PHPUnit/SimpleTest 之类简单多了,一定要找时间试试 :D

  3. on 20 Sep 2006 at 10:35 am 3.crazytang said …

    标题:运行测试文件,好像有问题


    代码:
    C:\webtest\testcases>webtest -buildfile webtest1.xml
    \"java.exe\" -Xms64M -Xmx256M -cp \"C:\webtest\bin\..\lib\ant-launcher.jar\" -Dant.l
    ibrary.dir=\"C:\webtest\bin\..\lib\" org.apache.tools.ant.launch.Launcher -nouserl
    ib -lib \"C:\webtest\bin\..\lib\build;C:\webtest\bin\..\lib\build\clover.jar\" -bu
    ildfile webtest1.xml
    Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\j2re1.4
    .2_04\lib\tools.jar
    Buildfile: webtest1.xml

    BUILD FAILED
    C:\webtest\testcases\webtest1.xml:13: Cannot find C:\webtest\testcases\192.168.1
    .6/lib/taskdef.xml imported from C:\webtest\testcases\webtest1.xml

    Total time: 0 seconds

  4. on 20 Sep 2006 at 11:07 am 4.mmpower said …

    标题:oops,你需要JDK,光JRE还不行

    tools.jar是JDK里带的,ant需要JDK.[/list]

  5. on 26 Sep 2006 at 5:35 pm 5.djm said …

    标题:运行成功,但是好像很多语法。

    要写的代码好像很多哦!?
    我要研究一下它的xml格式。
    还有import里的文件还不知道怎么用了。

  6. on 28 Sep 2006 at 2:12 pm 6.hick said …

    标题:在我的机器上也提示找不到 tools.jar, 但是最终成功了

    在我的机器上也提示找不到 tools.jar, 但是最终成功了。
    不知道是不是因为没用到某些功能,我是用 canoo 自带的 sample 测试的。

    D:\Program\Canoo\doc\samples>webtest -buildfile installtest.xml
    \"java.exe\" -Xms64M -Xmx256M -cp \"D:\Program\Canoo\bin\..\lib\ant-launcher.jar\" -
    Dant.library.dir=\"D:\Program\Canoo\bin\..\lib\" org.apache.tools.ant.launch.Launc
    her -nouserlib -lib \"D:\Program\Canoo\bin\..\lib\build;D:\Program\Canoo\bin\..\l
    ib\build\clover.jar\" -buildfile installtest.xml
    Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.5.
    0_07\lib\tools.jar
    Buildfile: installtest.xml

    checkANT:

    mayPrintANTError:

    checkWebTest:
    [echo] webtest.home is D:\Program\Canoo\doc\samples/../..
    Overriding previous definition of reference to ant.PropertyHelper
    Overriding previous definition of reference to ant.PropertyHelper

    all:

    BUILD SUCCESSFUL
    Total time: 7 seconds

  7. on 28 Sep 2006 at 2:42 pm 7.hick said …

    标题:安装完 jdk 需要设置 JAVA_HOME 环境变量

    否则还是会报 Unable to locate tools.jar 的错误

Trackback This Post | Subscribe to the comments through RSS Feed

Leave a Reply

校验码:  

Buy movie . Why buy movies at the store while you can download complete movies at our home? You can pay with your credit card. Lowest prices over the Internet.

21 queries in 0.146 seconds.© 2004-2008.   海归博客. RSS Comments RSS