如何在所有浏览器中运行单元测试?

发布于 2024-11-02 08:26:09 字数 107 浏览 1 评论 0原文

我从未使用过 Selenium,但我猜它是用于模拟所有浏览器中的用户交互。

这就像集成测试。

但是如何以自动化的方式在所有浏览器上测试您的 js 库/框架(单元测试)?

I've never used Selenium but I guess it's for simulating user interaction in all browsers.

That's like integration tests.

But how do you test your js libraries/frameworks (unit testing) on all the browsers in an automated way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

苏佲洛 2024-11-09 08:26:09

对于单元测试,您可以尝试 http://code.google.com/p/ js-测试驱动程序/

JsTestDriver 由一个 JAR 文件组成,其中包含您开始使用所需的所有内容。有关命令行选项的深入讨论,请参阅入门。

这里概述了 JsTestDriver 在运行时如何工作...

For unit-testing you can try http://code.google.com/p/js-test-driver/

JsTestDriver consist of a single JAR file which contains everything you need to get started. For in depth discussion of command line option see GettingStarted.

Here is an overview of how JsTestDriver works at runtime...

烟沫凡尘 2024-11-09 08:26:09

您可以查看 TestSwarm

我正在从事的项目:TestSwarm...

它的构造非常简单。它是一个愚蠢的 JavaScript 客户端,不断地对中央服务器执行 ping 操作,以寻找更多要运行的测试。服务器收集测试套件并将它们发送到各自的客户端。

收集所有测试套件。例如,1 个“提交”可以有 10 个与之关联的测试套件(并分发到选定的浏览器)...

这种结构的好处是它能够以容错方式工作。客户可以来来去去。在任何给定时间都可能没有 Firefox 2 连接,而在其他时间可能有 30 个。作业会根据负载的需要进行排队和分配。此外,客户端足够简单,能够在移动设备上运行(同时完全与测试框架无关)...

You can have a look at TestSwarm:

project that I’m working on: TestSwarm...

Its construction is very simple. It’s a dumb JavaScript client that continually pings a central server looking for more tests to run. The server collects test suites and sends them out to the respective clients.

All the test suites are collected. For example, 1 “commit” can have 10 test suites associated with it (and be distributed to a selection of browsers)...

The nice thing about this construction is that it’s able to work in a fault-tolerant manner. Clients can come-and-go. At any given time there might be no Firefox 2s connected, at another time there could be thirty. The jobs are queued and divvied out as the load requires it. Additionally, the client is simple enough to be able to run on mobile devices (while being completely test framework agnostic)...

昵称有卵用 2024-11-09 08:26:09

The best one imo is the one from YUI : http://developer.yahoo.com/yui/3/test/
But doing unit-testing in every browser is kind of hard... Most people just test with it during development and just use node.js to test later on in case they broke something.

樱桃奶球 2024-11-09 08:26:09

As the referenced post in a previous article suggests, you could use js-test-driver.
Its specifically for JavaScript unit testing across multiple browsers, exactly what you want. I have messed around with it and it is pretty good. I haven't done any serious commercial testing in it though.

想你只要分分秒秒 2024-11-09 08:26:09

对于单元测试,您应该考虑不加载浏览器来进行测试的解决方案。

您可以查看 RhinoUnit 之类的东西 - http://code.google.com/p/rhinounit< /a>

另请参阅 Dojo Object Harness (DOH) 单元测试框架 http://dojotoolkit.org/reference-guide/util/doh.html

在这里查看一个类似的问题,它可以让您了解如何使用 TDD js - 用于 TDD 的 JavaScript 单元测试工具

For unit testing you should look at solutions that do not load up a browser to do the tests.

You can look at something like RhinoUnit for that - http://code.google.com/p/rhinounit

Also have a look at Dojo Object Harness (DOH) unit test framework http://dojotoolkit.org/reference-guide/util/doh.html

Look at a similar question here which can give you an idea on how to TDD js - JavaScript unit test tools for TDD

想挽留 2024-11-09 08:26:09

它不再被积极维护,但我仍然对 JSUnit 进行 Javascript 单元测试感到满意: https://github.com /pivotal/jsunit

它包括一个可以在浏览器中运行的 HTML/Javascript 框架,以及一个可以从 ant 调用的基于 java 的测试运行程序。

It's no longer actively maintained, but I've still been happy with JSUnit for Javascript unit testing: https://github.com/pivotal/jsunit

It includes both an HTML/Javascript framework you can run in the browser, and a java-based test runner that you can invoke from ant.

别再吹冷风 2024-11-09 08:26:09

To test multiple browsers in parallel you would Selenium Grid. Please take a look here: http://selenium-grid.seleniumhq.org/step_by_step_installation_instructions_for_windows.html for step by step instructions on how to use it.

沉默的熊 2024-11-09 08:26:09

到目前为止我还没有使用过它,它仍然处于测试阶段,但是 FuncUnit 将自己声明为“基于 qUnit、Selenium 和 jQuery 的功能测试套件”。

还有一个信息图解释它是如何工作的

也许这就是你想要的东西? github 存储库 似乎相当活跃。

I haven't used it so far, and it is still in beta, but FuncUnit declares itself as "A functional test suite based of qUnit, Selenium and jQuery".

There is also an infographic explaining how it works

Maybe it is something what you want? The github repo seems to be quite active.

南街女流氓 2024-11-09 08:26:09

您应该检查 http://saucelabs.com 它是一个云基础 selenium 环境,允许您构建测试然后上传它们,在任意数量的浏览器中运行它们。

You should check http://saucelabs.com its a cloud base selenium environment that allow you to build your test and then upload them, run them in as many browsers as you want.

未央 2024-11-09 08:26:09

您应该考虑 crossbrowsertesting.com 提供的功能
(它不是免费的)。对于 js 测试,请尝试 JsUnit (http://www.jsunit.net/)。

引自其主页

JsUnit 是客户端(浏览器内)JavaScript 的单元测试框架。它本质上是 JUnit 到 JavaScript 的端口。还包括一个用于在多个浏览器和运行不同操作系统的多台计算机上自动执行测试的平台。

You should consider the capabilities offered by crossbrowsertesting.com
(It is not for free). For js testing try JsUnit (http://www.jsunit.net/).

Quoted from its homepage

JsUnit is a Unit Testing framework for client-side (in-browser) JavaScript. It is essentially a port of JUnit to JavaScript. Also included is a platform for automating the execution of tests on multiple browsers and mutiple machines running different OSs.

夏末的微笑 2024-11-09 08:26:09

正如人们已经说过的,你应该使用 JsTestDriver。它有自己的测试系统,但您可以使用其他测试库,例如 Jasmine ( http://pivotal .github.com/jasmine/ )。您可以在此处找到 JsTestDriver 适配器列表:http://code。 google.com/p/js-test-driver/wiki/XUnitCompatibility

As people have already said so, you should use JsTestDriver. It has it's own test system, but you can use other test libraries with it, for example Jasmine ( http://pivotal.github.com/jasmine/ ). You can find a list of adaptors for JsTestDriver here: http://code.google.com/p/js-test-driver/wiki/XUnitCompatibility

蔚蓝源自深海 2024-11-09 08:26:09

我会选择 QUnit,这是 jQuery 使用的。我已经在很多桌面浏览器以及 iPhone 和 Android 手机上运行过它。

有一些很棒的教程 它可以轻松地与 js-test-driver 之类的东西集成。 QUnit 是根据 JUnit 和所有其他 xUnit 测试框架(如 PHPUnit)建模的,因此很容易掌握 API。

基本语法如下:

test("my first test", function() {
  var str = "hello";
  equals( "hello", str, "Should be hello" );
});

它看起来也很不错:

QUnit截图

I'd go for QUnit, which is what jQuery uses. I've ran it on lots of desktop browsers as well as iPhones and Android phones.

There's some great tutorials and it can be integrated easily with things like js-test-driver. QUnit is modeled after JUnit and all the other xUnit testing frameworks (like PHPUnit) so it's easy to pick up the API.

The basic syntax is as follows:

test("my first test", function() {
  var str = "hello";
  equals( "hello", str, "Should be hello" );
});

It also looks quite nice:

QUnit screenshot

ら栖息 2024-11-09 08:26:09

专门从事跨浏览器测试的公司很少。

http://browserling.com/

http://www.browserstack.com/

http://saucelabs.com/ (此处已提到)

http://browsershots.org/

http://www.browsercam.com/

http://browserseal.com /

使用您想要的任何测试库。

There are few companies that specialize in cross browser testing.

http://browserling.com/

http://www.browserstack.com/

http://saucelabs.com/ (already mentioned here)

http://browsershots.org/

http://www.browsercam.com/

http://browserseal.com/

Use whatever testing lib you want.

计㈡愣 2024-11-09 08:26:09

Selenium 或 SauceLabs 等不是单元测试。它们是功能/集成测试解决方案。

您需要抽象 DOM 等外部用法来对 javascript 进行单元测试。

编写您的测试,以便它们可以通过配置使用任何外部库,例如 jquery。这样,您就可以对逻辑进行单元测试,而无需接触任何外部性,并且还可以测试跨浏览器测试。

Selenium or SauceLabs etc are not unit testing. They are functional/integration testing solutions.

You need to abstract your external usages like DOM to unit test javascript.

Write your tests so that they can use any external library like jquery by configuration. So that, you can unit test your logic without touching any externality and you can also both test cross-browser testing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文