0

我刚开始使用 JsTestDriver,我创建了非常简单的演示代码来查看我是否正确配置了我的环境。然而,当 Firefox 启动(通过 JsTestDriver)“Firefox 启动时意外关闭”时,大约 40-50% 的时间我会收到以下错误。

如果我使用 Chrome,则不会出现此错误。

我的环境包括:

  • VirtualBox 4.1.18 运行 Ubuntu 10.04.4 LTS 32bit
  • 火狐 13.0.1
  • JsTestDriver-1.3.4.b
  • openjdk-6-jre-headless

我正在执行:

java -jar /home/developer/bin/JsTestDriver.jar --port 9876 --browser /usr/bin/firefox --tests all --testOutput results

我的 JsTestDriver 配置是:

server: http://localhost:9876

load:
  - src/*.js

test:
  - test/*.js

timeout: 10

源代码(正在测试的代码)是:

Person = function()
{
    this.firstName = "";
    this.lastName = "";

    this.fullName = function()
    {
        if((this.firstName != "") && (this.lastName != ""))
        {
            return this.lastName + ", " + this.firstName;
        }

        var name = this.firstName + " " + this.lastName;
        return name.trim();
    }
};

测试代码(基于 JsTestDriver 的代码)是:

PersonTest = TestCase("PersonTest");

PersonTest.prototype.testFullName = function()
{
    fixture = new Person();
    fixture.firstName = "John";
    fixture.lastName = "Doe";

    assertEquals("Doe, John", fixture.fullName());
};

PersonTest.prototype.testFullName_FirstNameOnly = function()
{
    fixture = new Person();
    fixture.firstName = "John";

    assertEquals("John", fixture.fullName());
};

PersonTest.prototype.testFullName_LastNameOnly = function()
{
    fixture = new Person();
    fixture.lastName = "Doe"

    assertEquals("Doe", fixture.fullName());
};

谢谢!

4

1 回答 1

0

您的问题可能在于每次运行测试时都在打开浏览器打开服务器。我认为一个不太容易出错的解决方案是启动您的服务器并让它捕获一些浏览器,然后让它运行。然后,您可以根据需要对该服务器运行测试。我们的工作解决方案涉及三个始终运行 IE7、IE8、IE9、Firefox 和 Chrome 的虚拟机,我们的 Maven 构建过程在每次构建时运行我们的 javascript 单元测试。此外,请确保您也始终使用“--reset”参数。它将使您的浏览器保持新鲜。我写了一篇文章,展示了如何将 QUnit、Requirejs 和代码覆盖与独立于 Maven 的 JSTD 集成:js-test-driver+qunit+coverage+requirejs。希望能帮助到你。

于 2012-06-30T01:38:49.783 回答