本文介绍了用于TDD的JavaScript单元测试工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我已经研究并考虑了许多JavaScript单元测试和测试工具,但一直无法找到合适的选项来保持完全符合TDD标准。那么,是否有完全符合TDD标准的JavaScript单元测试工具?解决方案 而不是 Yolpo是一个可视化javascript执行的工具。我们鼓励Javascript API开发人员编写用例来展示和告知他们的API。这些用例构成了回归测试的基础。 内置支持ES2015的未来测试跑步者。尽管JavaScript是单线程的,但由于其异步特性,Node.js中的IO可以并行发生。 AVA利用这一点并同时运行您的测试,这对IO重测试尤其有用。此外,测试文件作为单独的进程并行运行,为每个测试文件提供更好的性能和隔离的环境。 最小化快速 简单的测试语法 同时运行测试 强制编写原子测试 无隐式全局 每个测试文件的隔离环境 在ES2015中编写测试 承诺支持 生成器功能支持 异步功能支持 可观察支持 增强断言 可选TAP o utput 清理堆栈跟踪 ,用于在Rails项目中进行测试。 Jasmine规范可以从html页面(以qUnit方式)或从测试运行器(作为Karma)运行。如果您有使用此测试框架的经验,请提供更多信息:) 项目主页: http://jasmine.github.io/ QUnit QUnit专注于在浏览器中测试JavaScript,同时为开发人员提供尽可能多的便利。来自网站的Blurb: QUnit分享一些历史记录TestSwarm(上图):项目主页: http://qunitjs.com/ Sinon 另一个很棒的工具是 sinon.js 作者:Christian Johansen,测试驱动的JavaScript的作者发展。自己最好描述: 实习生 实习生网站提供与此列表中其他测试框架的直接功能比较。它提供了比任何其他基于JavaScript的测试系统更多的开箱即用功能。 JEST 一个新的但非常强大的测试框架。它允许基于快照的测试,这也提高了测试速度并在测试方面创造了新的动态 查看他们的一个演讲: https://www.youtube.com/watch?v=cAKYQpTC7MA 更好的是:使用入门 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. So, is there a JavaScript unit test tool that is fully TDD compliant? 解决方案 Karma or ProtractorKarma is a JavaScript test-runner built with Node.js and meant for unit testing.The Protractor is for end-to-end testing and uses Selenium Web Driver to drive tests.Both have been made by the Angular team. You can use any assertion-library you want with either.Screencast: Karma Getting startedrelated:Should I be using Protractor or Karma for my end-to-end testing?Can Protractor and Karma be used together?pros:Uses node.js, so compatible with Win/OS X/LinuxRun tests from a browser or headless with PhantomJSRun on multiple clients at onceOption to launch, capture, and automatically shut down browsersOption to run server/clients on development computer or separatelyRun tests from a command line (can be integrated into ant/maven)Write tests xUnit or BDD styleSupports multiple JavaScript test frameworksAuto-run tests on saveProxies requests cross-domainPossible to customize:Extend it to wrap other test-frameworks (Jasmine, Mocha, QUnit built-in)Your own assertions/refutesReportersBrowser LaunchersPlugin for WebStormSupported by Netbeans IDECons:Does not support NodeJS (i.e. backend) testingNo plugin for Eclipse (yet)No history of previous test results mocha.jsI'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.List of features, as reported by its website:browser supportsimple async support, including promisestest coverage reportingstring diff supportjavascript # API for running testsproper exit status for CI support etcauto-detects and disables coloring for non-ttysmaps uncaught exceptions to the correct test caseasync test timeout supporttest-specific timeoutsgrowl notification supportreports test durationshighlights slow testsfile watcher supportglobal variable leak detectionoptionally run tests that match a regexpauto-exit to prevent "hanging" with an active loopeasily meta-generate suites & test-casesmocha.opts file supportclickable suite titles to filter test executionnode debugger supportdetects multiple calls to done()use any assertion library you wantextensible reporting, bundled with 9+ reportersextensible test DSLs or "interfaces"before, after, before each, after each hookarbitrary transpiler support (coffee-script etc)TextMate bundleyolpoYolpo is a tool to visualize the execution of javascript. Javascript API developers are encouraged to write their use cases to show and tell their API. Such use cases forms the basis of regression tests.AVAFuturistic test runner with built-in support for ES2015. Even though JavaScript is single-threaded, IO in Node.js can happen in parallel due to its async nature. AVA takes advantage of this and runs your tests concurrently, which is especially beneficial for IO heavy tests. 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 fastSimple test syntaxRuns tests concurrentlyEnforces writing atomic testsNo implicit globalsIsolated environment for each test fileWrite your tests in ES2015Promise supportGenerator function supportAsync function supportObservable supportEnhanced assertsOptional TAP o utputClean stack tracesBuster.jsA JavaScript test-runner built with Node.js. 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. Instead of using assert(!...) or expect(...).not..., it uses refute(...) which is a nice twist imho.Screencast: Buster.js Getting started (2:45)pros:Uses node.js, so compatible with Win/OS X/LinuxRun tests from a browser or headless with PhantomJS (soon)Run on multiple clients at onceSupports NodeJS testingDon't need to run server/clients on development computer (no need for IE)Run tests from a command line (can be integrated into ant/maven)Write tests xUnit or BDD styleSupports multiple JavaScript test frameworksDefer tests instead of commenting them outSinonJS built-inAuto-run tests on saveProxies requests cross-domainPossible to customize:Extend it to wrap other test-frameworks (JsTestDriver built in)Your own assertions/refutesReporters (xUnit XML, traditional dots, specification, tap, TeamCity and more built-in)Customize/replace the HTML that is used to run the browser-testsTextMate and Emacs integrationCons:Stil in beta so can be buggyNo 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 May 2014* TestSwarm is also a Continuous 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.TestSwarmhttps://github.com/jquery/testswarmTestSwarm is officially no longer under active development as stated on their GitHub webpage. They recommend Karma, browserstack-runner, or Intern.JasmineThis is a behavior-driven framework (as stated in quote below) that might interest developers familiar with Ruby or Ruby on Rails. The syntax is based on RSpec that are used for testing in Rails projects.Jasmine specs can be run from an html page (in qUnit fashion) or from a test runner (as Karma).If you have experience with this testing framework, please contribute with more info :)Project home: http://jasmine.github.io/QUnitQUnit focuses on testing JavaScript in the browser while providing as much convenience to the developer as possible. Blurb from the site:QUnit shares some history with TestSwarm (above):Project home: http://qunitjs.com/SinonAnother great tool is sinon.js by Christian Johansen, the author of Test-Driven JavaScript Development. Best described by himself:InternThe Intern Web site provides a direct feature comparison to the other testing frameworks on this list. It offers more features out of the box than any other JavaScript-based testing system.JESTA new but yet very powerful testing framework. It allows snapshot based testing as well this increases the testing speed and creates a new dynamic in terms of testingCheck out one of their talks: https://www.youtube.com/watch?v=cAKYQpTC7MABetter yet: Getting Started 这篇关于用于TDD的JavaScript单元测试工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-22 06:24