maven - 集成 maven/qunit/phantomjs 的更好方法?

标签 maven qunit phantomjs

我一直在研究在我们的 maven CI 环境中进行 JS 单元测试的最佳方法。我目前在我的 Maven 项目中拼凑了以下内容:

  • qunit 资源(JS/CSS 文件)
  • 如果需要,使用 html 夹具 qunit 测试 html 文件(每个被测文件一个)
  • index html 文件,它引用测试 html 文件作为超链接的有序列表
  • PhantomJS 运行文件,其中:
  • 打开索引 html 文件并解析出测试文件列表
  • 打开每个测试文件
  • 每个文件的qunit测试结果截图
  • 如果有任何失败,退出状态为“1”
  • 如果没有失败,退出状态为“0”
  • 如果未安装 phantomjs,shell 文件将以“0”退出,如果已安装,将调用 phantomjs 测试
  • 在构建的测试阶段更改 pom.xml 以运行 phantomjs 测试:
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <id>PhantomJS Unit Testing</id>
                    <phase>test</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <executable>${project.basedir}/src/main/webapp/unittest/phantomcheck</executable>
                <arguments>
                    <argument>${project.basedir}/src/main/webapp/unittest/qunit-runner.js</argument>
                    <argument>${project.basedir}/src/main/webapp/unittest/tests/index.html</argument>
                    <argument>${project.build.directory}/surefire-reports</argument>
                </arguments>
            </configuration>
        </plugin>
    </plugins>
    

  • 所以,这很好用。它在我们的开发和构建机器上的构建期间运行 qunit 测试(只要安装了 PhantomJS)。测试在 headless 浏览器环境中运行,对 qunit 测试没有限制。我见过的其他 maven/qunit 集成由于在 Rhino 或其他 JS 环境中运行测试而失败,这些环境限制了我们可以编写的测试类型。另外 phantomjs 使我们能够获得测试运行的屏幕截图,这有助于对任何故障进行故障排除。

    我的方法的缺点是需要在构建/开发机器上安装 PhantomJS。我不知道如何将 phantomJS 捆绑到一个依赖项中,这样开发人员就不必担心安装 PhantomJS。任何人都可以在这个方向上插入我吗?我该如何开始?

    最佳答案

    phantomjs-maven-plugin提供 install安装 phantomjs 的目标,因此您不需要预先安装它。安装 phantomjs 后,它会设置一个属性,其中包含其他插件可以使用的可执行文件的路径。它还有一个 exec执行 phantomjs 脚本的目标。完全披露:我编写了插件。

    关于maven - 集成 maven/qunit/phantomjs 的更好方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8525311/

    相关文章:

    java - maven 忽略 pom.xml 中的源级别

    maven - IntelliJ Maven 依赖自动补全

    javascript - qUnit:运行测试子集?

    node.js - 我在 Azure 上有这些模块,为什么我收到 Recipe phantom-pdf was not found.?

    android - 使用 Maven 为不同环境(开发、暂存、生产)构建应用程序

    java - 无法解析对值 :$akka. 的替换 stream-blocking io dispatcher

    javascript - QUnit、Sinon.js 和 Backbone 单元测试受挫 : sinon spy appears to fail to detect Backbone Model event callbacks

    javascript - 尽管在测试期间发现错误,但测试结果成功

    node.js - Phantom JS for Node,使用打印样式表?

    Selenium java + PhantomJS - phantomjs ://platform/console++. js:263 错误