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