Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

javascript - TDD的JavaScript单元测试工具(JavaScript unit test tools for TDD)

I've looked into and considered many JavaScript unit tests and testing tools, but have been unable to find a suitable option to remain fully TDD compliant.

(我研究并考虑了许多JavaScript单元测试和测试工具,但一直无法找到合适的选项来保持与TDD的完全兼容。)

So, is there a JavaScript unit test tool that is fully TDD compliant?

(那么,是否有一个完全符合TDD的JavaScript单元测试工具?)

  ask by community wiki translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Karma or Protractor(业力量角器)

Karma is a JavaScript test-runner built with Node.js and meant for unit testing.

(Karma是使用Node.js构建的JavaScript测试运行程序,用于单元测试。)

The Protractor is for end-to-end testing and uses Selenium Web Driver to drive tests.

(量角器用于端到端测试,并使用Selenium Web Driver驱动测试。)

Both have been made by the Angular team.

(两者都是由Angular团队制作的。)

You can use any assertion-library you want with either.

(您可以在任何一个声明库中使用。)

Screencast: Karma Getting started

(截屏视频: 业力入门)

related :

(相关 :)

pros :

(优点 :)

  • Uses node.js, so compatible with Win/OS X/Linux

    (使用node.js,因此与Win / OS X / Linux兼容)

  • Run tests from a browser or headless with PhantomJS

    (使用PhantomJS从浏览器运行测试或无头运行)

  • Run on multiple clients at once

    (一次在多个客户端上运行)

  • Option to launch, capture, and automatically shut down browsers

    (选择启动,捕获和自动关闭浏览器)

  • Option to run server/clients on development computer or separately

    (选择在开发计算机上或单独运行服务器/客户端)

  • Run tests from a command line (can be integrated into ant/maven)

    (从命令行运行测试(可以集成到ant / maven中))

  • Write tests xUnit or BDD style

    (编写测试xUnit或BDD样式)

  • Supports multiple JavaScript test frameworks

    (支持多种JavaScript测试框架)

  • Auto-run tests on save

    (保存时自动运行测试)

  • Proxies requests cross-domain

    (代理请求跨域)

  • Possible to customize:

    (可以自定义:)

    • Extend it to wrap other test-frameworks (Jasmine, Mocha, QUnit built-in)

      (扩展它以包装其他测试框架(Jasmine,Mocha,内置QUnit))

    • Your own assertions/refutes

      (您自己的断言/反驳)

    • Reporters

      (记者)

    • Browser Launchers

      (浏览器启动器)

  • Plugin for WebStorm

    (WebStorm插件)

  • Supported by Netbeans IDE

    (受Netbeans IDE支持)

Cons :

(缺点 :)

mocha.js(mocha.js)

I'm totally unqualified to comment on mocha.js's features, strengths, and weaknesses, but it was just recommended to me by someone I trust in the JS community.

(我完全没有资格评论mocha.js的功能,优点和缺点,但是我信任JS社区的人才向我推荐了它。)

List of features, as reported by its website:

(网站列表报告的功能列表:)

  • browser support

    (浏览器支持)

  • simple async support, including promises

    (简单的异步支持,包括承诺)

  • test coverage reporting

    (测试覆盖率报告)

  • string diff support

    (字符串差异支持)

  • javascript # API for running tests

    (javascript#用于运行测试的API)

  • proper exit status for CI support etc

    (CI支持的正确退出状态等)

  • auto-detects and disables coloring for non-ttys

    (自动检测并禁用非tty的着色)

  • maps uncaught exceptions to the correct test case

    (将未捕获的异常映射到正确的测试用例)

  • async test timeout support

    (异步测试超时支持)

  • test-specific timeouts

    (特定于测试的超时)

  • growl notification support

    (咆哮通知支持)

  • reports test durations

    (报告测试时间)

  • highlights slow tests

    (突出测试缓慢)

  • file watcher support

    (文件观察器支持)

  • global variable leak detection

    (全局变量泄漏检测)

  • optionally run tests that match a regexp

    ((可选)运行与正则表达式匹配的测试)

  • auto-exit to prevent "hanging" with an active loop

    (自动退出以防止活动循环“挂起”)

  • easily meta-generate suites & test-cases

    (轻松生成元套件和测试用例)

  • mocha.opts file support

    (mocha.opts文件支持)

  • clickable suite titles to filter test execution

    (可点击的套件标题以过滤测试执行)

  • node debugger support

    (节点调试器支持)

  • detects multiple calls to done()

    (检测到对done()的多次调用)

  • use any assertion library you want

    (使用您想要的任何断言库)

  • extensible reporting, bundled with 9+ reporters

    (可扩展的报告,与9+个记者捆绑在一起)

  • extensible test DSLs or "interfaces"

    (可扩展的测试DSL或“接口”)

  • before, after, before each, after each hook

    (之前,之后,每个钩子之前,之后)

  • arbitrary transpiler support (coffee-script etc)

    (任意翻译器支持(咖啡脚本等))

  • TextMate bundle

    (TextMate捆绑包)

yolpo(约尔波)

约尔波

This no longer exists, redirects to sequential.js instead

(不再存在,而是重定向到serial.js)

Yolpo is a tool to visualize the execution of javascript.

(Yolpo是可视化javascript执行的工具。)

Javascript API developers are encouraged to write their use cases to show and tell their API.

(鼓励Javascript API开发人员编写用例来展示和讲述他们的API。)

Such use cases forms the basis of regression tests.

(这样的用例构成了回归测试的基础。)

AVA(AVA)

AVA徽标

Futuristic test runner with built-in support for ES2015.

(具有对ES2015的内置支持的未来派测试运行程序。)

Even though JavaScript is single-threaded, IO in Node.js can happen in parallel due to its async nature.

(即使JavaScript是单线程的,由于其异步特性,Node.js中的IO仍可以并行发生。)

AVA takes advantage of this and runs your tests concurrently, which is especially beneficial for IO heavy tests.

(AVA利用此优势并同时运行您的测试,这对于IO大量测试特别有用。)

In addition, test files are run in parallel as separate processes, giving you even better performance and an isolated environment for each test file.

(此外,测试文件作为单独的进程并行运行,从而为每个测试文件提供了更好的性能和隔离的环境。)

  • Minimal and fast

    (最小且快速)

  • Simple test syntax

    (简单的测试语法)

  • Runs tests concurrently

    (同时运行测试)

  • Enforces writing atomic tests

    (加强编写原子测试)

  • No implicit globals

    (没有隐式全局变量)

  • Isolated environment for each test file

    (每个测试文件的隔离环境)

  • Write your tests in ES2015

    (在ES2015中编写测试)

  • Promise support

    (承诺支持)

  • Generator function support

    (发电机功能支持)

  • Async function support

    (异步功能支持)

  • Observable support

    (可观察的支持)

  • Enhanced asserts

    (增强断言)

  • Optional TAP o utput

    (可选的TAP输出)

  • Clean stack traces

    (清除堆栈痕迹)

Buster.js(Buster.js)

A JavaScript test-runner built with Node.js.

(使用Node.js构建的JavaScript测试运行程序。)

Very modular and flexible.

(非常模块化和灵活。)

It comes with its own assertion library, but you can add your own if you like.

(它带有自己的断言库,但是您可以根据需要添加自己的断言库。)

The assertions library is decoupled, so you can also use it with other test-runners.

(<a href="https://stack


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...