跳至主要内容

javascript unit test framework introducing, from stackoverflow:


see: http://stackoverflow.com/questions/300855/looking-for-a-better-javascript-unit-test-tool

Buster.js

Very similar server/client concept as JsTestDriver (see further down). Except that the server is built with JavaScript (node.js) instead of Java, and the API follows JS best practices to a much higher degree.
A browser JavaScript testing toolkit. It does browser testing with browser automation (think JsTestDriver), qunit style static html page testing, testing in headless browsers (phantomjs, jsdom, ...), and more. Take a look at the overview!
A Node.js testing toolkit. You get the same test case library, assertion library, etc. This is also great for hybrid browser and Node.js code. Write your test case with Buster.JS and run it both in Node.js and in a real browser.
Screencast: Buster.js Getting started (2:45)
pros:
  • Uses node.js, so compatible with Win/OS X/Linux
  • Run tests from browser or headless with PhantomJS (soon)
  • Run on multiple clients at once
  • Supports NodeJS testing
  • Don't need to run server/clients on development computer (no need for IE)
  • Run tests from command line (can be integrated in ant/maven) Write tests xUnit or BDD style
  • Supports multiple JavaScript test frameworks
  • Defer tests instead of commenting them out
  • SinonJS built in
  • Auto-run tests on save
  • Proxies requests cross-domain
  • Possible to customize:
    • Extend it to wrap other test-frameworks (JsTestDriver built in)
    • Your own assertions/refutes
    • Reporters (xunit XML, traditional dots, specification, tap, teamcity and more built in)
    • Customize/replace the HTML that is used to run the browser-tests
  • TextMate and Emacs integration
cons:
  • Stil in beta, so can be buggy
  • No plugin for Eclipse/IntelliJ (yet)
  • Doesn't group results by os/browser/version like TestSwarm *. It does however print out the browser name and version in the test results.
  • No history of previous test results like TestSwarm *
  • Doesn't fully work on windows as of nov 2012
* TestSwarm is also a Continuos Integration server, while you need a separate CI server for Buster.js. It does however output xUnit XML reports, so it should be easy to integrate with Hudson, Bamboo or other CI servers.

Testacular

Again, very similar server/client concept as JsTestDriver (see further down). Like Buster.js the server is built with JavaScript (node.js).
pros:
  • Uses node.js, so compatible with Win/OS X/Linux
  • Run tests from browser or headless with PhantomJS
  • Run on multiple clients at once
  • Option to launch, capture, and automatically shutdown browsers
  • Option to run server/clients on development computer or separately
  • Run tests from command line (can be integrated in ant/maven)
  • Write tests xUnit or BDD style
  • Supports multiple JavaScript test frameworks
  • Auto-run tests on save
  • Proxies requests cross-domain
  • Possible to customize:
    • Extend it to wrap other test-frameworks (Jasmine, Mocha, QUnit built-in)
    • Your own assertions/refutes
    • Reporters
    • Browser Launchers
  • Plugin for WebStorm
cons:
  • Does not supports NodeJS testing
  • No plugin for Eclipse (yet)
  • No history of previous test results

TestSwarm

John Resig (jQuery) has created a tool for distributed JavaScript testing, TestSwarm. Mainly for open source JavaScript projects, but TestSwarm is open source, so you can set up a server yourself for corporate testing. Although this might require that you to do some modifications.
pros:
  • Continuos integration server for JavaScript
  • Supports all major browsers/operating systems
  • Run on multiple clients at once
  • Don't need to run server/clients on development computer (no need for IE)
  • Automatic run tests on all clients when you commit something (or whenever you modify the script to run the tests)
  • Show history of test results pr commit
  • Supports multiple JavaScript test frameworks
  • Have test results for OS and browser versions
  • Crowdsource to test in a multitude of browsers
cons:
  • Can not break your build through ant/maven
  • Don't notice the test fail before commit
  • No IDEplug-in
TestSwarm architecture:
alt text

JsTestDriver

Some people at Google have also started on a distributed JavaScript tool, JsTestDriver. It is similar to TestSwarm, that it has a server, and clients connected. But it also has support for running tests from command line and plugins for Eclipse and IntelliJ!
pros:
  • Supports all major browsers/operating systems
  • Run on multiple clients at once
  • Don't need to run server/clients on development computer (no need for IE)
  • Run tests from command line (jar) (can be integrated in ant/maven)
  • Eclipse plugin
  • IntelliJ plugin
  • Supports multiple JavaScript test frameworks
cons:
  • Doesn't show results for os or browser version. Only browser names. It does however print out the version in the test results.
  • No history of previous test results
  • Very low project activity
Overview of how JsTestDriver works at runtime: alt text
Eclipse plugin screenshot:
alt text

YUI Yeti

Yahoo now has their own JavaScript test run server, Yeti. Built with node.js. It should be able to run your existing YUI-tests as they are, and works in multiple browsers. Since it runs from the command-line I guess it's mostly similar to JsTestDriver.
alt text
If you have experience with this test-runner, please contribute with more info :)

Jasmine

Jasmine
This is a test-runner that might interest developers familiar with Ruby or Ruby on Rails. The syntax is based on RSpec that's used for testing in Rails projects.
Jasmine is a behavior-driven development framework for testing your JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM.
If you have experience with this test-runner, please contribute with more info :)

QUnit

QUnit focuses on testing JavaScript in the browser, while providing as much convenience to the developer as possible. Blurb from the site:
QUnit is a powerful, easy-to-use JavaScript unit test suite. It's used by the jQuery, jQuery UI and jQuery Mobile projects and is capable of testing any generic JavaScript code
QUnit shares some history with TestSwarm (above):
QUnit was originally developed by John Resig as part of jQuery. In 2008 it got its own home, name and API documentation, allowing others to use it for their unit testing as well. At the time it still dependended on jQuery. A rewrite in 2009 fixed that, now QUnit runs completelty standalone. QUnit's assertion methods follow the CommonJS Unit Testing specification, which was to some degree influenced by QUnit.
Project home: http://qunitjs.com/

Sinon

Another great tool is sinon.js by Christian Johansen, the author of Test-Driven JavaScript Development. Best described by himself:
Standalone test spies, stubs and mocks for JavaScript. No dependencies, works with any unit testing framework.

评论

此博客中的热门博文

My childhood

"Each person's life is like a book; some people prefer to savor it slowly, while others like to gradually forget it. Looking back, I want to see if I can discern the trajectory of the world from my seemingly insignificant life. I am a child from the countryside, and perhaps most people cannot understand what my so-called countryside looks like. Indeed, the impressions of the countryside can be very different depending on the country, and moreover, more than 40 years have passed, during these 40 years of rapid development in China. A phrase suddenly comes to mind, 'I see him building tall buildings, I see him feasting, I see everything collapsing.' The place where I was born is a small town in the southwest of China, a town so small that it only has one street, and the widest part is only 3 meters. Paved with stone slabs, worn by many years of use, the slabs are not flat but rather filled with small bumps and hollows, yet strangely smooth. At the end of the street is a ...

youtube script covid

[INTRO - Soft Music Playing] Narrator: "In August 2020, during the COVID-19 pandemic in China, I experienced a series of events that revealed the overbearing, unreasonable, and ignorant aspects of government policies. This story unfolds my observations and experiences in Xinjiang since April, presented in a neutral and factual manner." [Scene Transition - Music Shifts to a More Reflective Tone] Narrator: "April 8th marked the end of my nearly three-month-long home quarantine in Wuhan, as the lockdown was finally lifted. With Xinjiang gradually reopening since March, my work required me to return there as soon as possible." [Visuals: Scenes of Empty Streets in Wuhan, Transitioning to Busy Airports] Narrator: "My journey back to Xinjiang was fraught with delays. The direct flight on China Southern Airlines kept getting postponed. Reluctantly, I had to transit through Xi'an. Before leaving, I reported my health status to the community in Changji City, where I ...

关于 6月16日香港大游行 统计

wikipedia: https://zh.wikipedia.org/wiki/2019年6月16日香港反對逃犯條例修訂草案遊行  主办单位公布游行有200万零1人参与,是香港史上主办方公布最多人参加的游行;而警方宣称游行人数仅有33.8万人[e],警方计算游行人数的方法惹来外媒如路透社[9]、BBC[21]、天下杂志等广泛不信任[22][23]。由于本游行仓促成行,不像6月9日与7月1日的游行有人工智能客观统计,加上这次大游行中人流不断溢出多条原定游行路线以外的街道,令统计人数工作更困难,本游行双方差距甚大的人数统计令到人工智能取代传统点算之议方兴未艾。[5][24]无论如何,此游行的人数是1997年回归以来人数最多则无疑问。众多第三方统计之中,路透社与一众日本传媒仅引用了在现场调试[5]人工智能系统的叶兆辉所提供的估算“50-80万人”. yahoo news: https://yahoo-news.com.hk/BBCChineseNews/4174/ 政府公布的數字往往會比遊行主辦方公布的數字低,偏差有時候會達數倍,一高一低的有關數字常引發爭議。例如,早些時候香港民間人權陣線(簡稱「民陣」)為反對《逃犯條例》修訂舉行數次遊行,對於6月16日舉行的遊行,主辦方「民陣」稱有約200萬人參加,香港警方卻說高峰期只有約33.8萬人。 此文还有历次游行主办方和警方的数据统计比较 Voa: https://www.voachinese.com/a/Hong-Kong-demonstration-numbers-20190709/4992522.html 香港游行人数之差,在近年来日益明显而引人关注。就在这次“两百万”人大游行之前一周,香港人举行了首次“反送中”大游行,游行人数之多,几乎占满了港岛几条主要干线。主办方说超过1百万人上街游行,警方说有24万。双方数字相差四分之三。值得关注的是,每次超大型游行后,总有示威者和警方发生冲突的报道,每次都有人受伤或被捕。 无论如此,从双方数字上来看,2019年6月爆发的两次大游行,(9日和16日),是香港主权移交以来也是香港有史以来最大规模的示威。 上次香港市民举行大规模游行示威,是2003年的反23条大游行。据主办方说那次游行参加人数为50万,警方说只有35万,双方当时的统计数...