`
zerozone
  • 浏览: 203436 次
  • 来自: 北京
社区版块
存档分类
最新评论
阅读更多

测试驱动开发是敏捷开发的一个重要实践。AJAX开发很困难,能否以及如何应用TDD帮助我们编写可测试的AJAX程序?

AJAX开发过程应用TDD有很多障碍:
自动测试工具难以支持众多
Ajax框架
不是所有
代码都能实现自动测试

网页主要由三部分组成:结构(
Structure)、表现(Presentation)和行为(Behavior)。分离这三部分为页面测试提供了基础。结构和行为部分基本可以实现自动测试,由于采用CSS实现分离(外观和表现)表现好像没有办法实现。

有人提到用JsUnit作为JavaScript代码的单元测试;用Selenium进行集成/回归测试。但好多Ajax框架已经设计开发出了组件,基于组件的单元测试工具更加有效。


Selenium不支持我们选用的一个商业AJAX/GUI FrameworkSeleniumAjax的支持如何?

欢迎讨论。

分享到:
评论
3 楼 hyysguyang 2007-08-02  
现在yui,jquery,dojo等都用自己的testcase框架,很是郁闷,为什么不统一用一个?比如jsunit就很好,而且很符合TDD的编程模式,有些地方它不能支持的话为什么不去想办法完善它呢?为啥还要自己实现一个?四分五裂的,java的世界就已经这样了.
yui的测试是2.3.0才新加的,它自身之前的版本都没有测试,因此ajax框架从未把yui考虑在内,现在有了测试了,我也要开始关注了。
2 楼 zerozone 2007-05-19  
fsword 写道
这个问题我们也遇到了,使用dojo编写的组件,用selenium测试有困难,这个问题现在还是没有解决。


试试Squish for Web!它对dojo的支持还不错。

测试工具的重点是执行断言。本来可以Squish录制的脚本中设置并执行断言。我简单测试过dojo框架Tree组件,录制测试脚本成功(点击不同的节点,展开/收缩节点)。不过我执行断言失败(对dojo了解太少)。

附上一段测试脚本(含断言方法,具体方法见Squish文档)。
function main()
{
    // load web application
    loadUrl(":http://www.smartclient.com/#_Welcome");
    
    // wait for the tree at the left to be available
    waitForObject(":isc_Rtable_TABLE");
    
    // Open "Editing" leaf in the tree
    clickTreeHandle(":isc_Rtable_TABLE", "Editing");
    snooze(1);
    
    // Click "Edit by row" item in the tree
    clickItem(":isc_Rtable_TABLE", "Edit by row");
    
    // wait for the editable table to be available at the right
    waitForObject(":isc_2Wtable_TABLE");
    
    // get reference to the table object
    table =  findObject(":isc_2Wtable_TABLE");
    
    // verify that a "Germany" item exists
    test.verify(! isNull(table.findItem("Germany")), "Found Germany in table");
    
    // verify that no "Deutschland" item exists yet
    test.verify(isNull(table.findItem("Deutschland")), "Not found Deutschland in table");
    
    // click on the "Germany" item to be able to edit it
    clickItem(":isc_2Wtable_TABLE", "Germany");
    
    // rename it to "Deutschland"
    setText(":isc_3B_text", "Deutschland");
    
    // click somewhere else to confirm
    clickItem(":isc_2Wtable_TABLE", "Japan");
    
    snooze(2);
    
    // retrieve reference to table again
    table =  findObject(":isc_2Wtable_TABLE");
    
    // verify that no "Germany" item exists anymore
    test.verify(isNull(table.findItem("Germany")), "Not found Germany in table");
    
    // verify that now a "Deutschland" item exists
    test.verify(! isNull(table.findItem("Deutschland")), "Found Deutschland in table");
    
    // close browser
    closeWindow(":[Window]");
}


顺便提一句,Squish是商业软件。你可以使用Evaluation版本。
1 楼 fsword 2007-05-18  
这个问题我们也遇到了,使用dojo编写的组件,用selenium测试有困难,这个问题现在还是没有解决。

相关推荐

Global site tag (gtag.js) - Google Analytics