12
返回列表 发新帖
楼主: Sky-Tiger

Ajax: Tools of the trade

[复制链接]
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
11#
 楼主| 发表于 2009-6-11 22:14 | 只看该作者
Crosscheck

Browser quirks and incompatibility are the bane of JavaScript developers. "It works in Firefox" is a common refrain. And although you might be able to run your tests across various operating systems with multiple browsers, maintaining a small server farm isn't trivial (or in some cases possible). All of the testing tools I've discussed thus far ultimately require a browser, and browser testing is notoriously slow. How do we overcome these dueling problems? Crosscheck to the rescue!

Crosscheck runs on the JVM, taking advantage of its ability to run JavaScript. Instead of spawning browsers, Crosscheck tries to simulate the various browser/OS combinations. Because it runs on the JVM and doesn't need to launch browsers, Crosscheck tests are much faster than other options. It also offers a simple automation path, making it a natural for inclusion on your CI box.

Crosscheck is a bit out of date, but if you're struggling with the multi-OS/browser issue, you owe it a chance.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
12#
 楼主| 发表于 2009-6-11 22:14 | 只看该作者
Testing the UI

Unit testing your JavaScript is a good idea, but sometimes -- say in complex Ajax interactions -- you just need to test at the user interface level. This section takes a quick stroll down the UI testing aisle. Although UI tests tend to be slow and somewhat brittle, they can also provide a helpful safety net.
Selenium

Selenium is a Web testing tool from the good people at ThoughtWorks. The Selenium project is broken up into the IDE (a Firefox add-on), Remote Control, and Grid. The IDE, shown in Figure 6, allows you to record an interaction and then either play it back in the default runner or export the test to any of six languages, where you can add them to your preferred testing tool.

Figure 6. The Selenium IDE
Figure 6. The Selenium IDE

Remote Control is a simple server that can launch and kill browsers, allowing you to easily incorporate Selenium tests into your CI server. Grid takes Remote Control to the next level by distributing tests to multiple machines, thus speeding up your test runs.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
13#
 楼主| 发表于 2009-6-11 22:14 | 只看该作者
YUI Test

Although YUI Test is primarily a unit-testing framework, it does allow some simulations of the DOM and user interaction. Although its capabilities are not as complete as Selenium's or Watir's, it's a viable option, especially if you're already using it to test your JavaScript.
Utilities

A number of tools that don't fit into any particular category are very useful in developing JavaScript. In this section we'll take a look at tools that verify that you aren't committing basic crimes against JavaScript, shrink your code for production, and keep your code well documented.
JSLint

It can be tricky to write good JavaScript. Any number of corner cases can easily slip by if you're not paying attention. Add in the sheer volume of poorly written JavaScript that has been copied and pasted over the years and, well, you get a mess. JSLint examines your code looking for common errors and bad practices. If you follow its advice, you'll have better code when you're done. Your feelings might be hurt in the process, but the final result is worth it. To test your code, you can either cut and paste it into the verifier box (shown in Figure 7) on the JSLint Web site (where you can set a plethora of options) or you can run it from the command line, thanks to Rhino (an open source JavaScript implementation written in Java).

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
14#
 楼主| 发表于 2009-6-11 22:16 | 只看该作者
Minifiers

As we write more and more JavaScript, we can end up with some pretty hefty page weights. And although more and more users are surfing on broadband, we still should minify our JavaScript. A variety of options, including Doug Crockford's JSMin and the YUI Compressor, are available. You may want to try a couple of different options until you settle on the one that works best for your code base and build system. Whichever tool you choose, do shrink your JavaScript before you go to production.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
15#
 楼主| 发表于 2009-6-11 22:16 | 只看该作者
Documentation tools

Documenting your JavaScript can be vital for long-term use and maintenance. You won't find anything as standard as Javadoc, but there are a variety of alternatives. The Prototype library uses PDoc, and YUI uses YUI Doc. You can incorporate either into your world; experiment to see what works best for you.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
16#
 楼主| 发表于 2009-6-11 22:16 | 只看该作者
In conclusion

The state of JavaScript development is strong. No longer are JavaScript developers relegated to alerts and a text editor. Today, we have IDEs with autocomplete, full-fledged debuggers, and a variety of testing tools. JavaScript is a first class citizen in any Web application and today, the JavaScript developers of the world have a top-notch set of tools for crafting world-class interactions.

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表