整合maven/qunit/phantomjs的更好方法? [英] Better way to integrate maven/qunit/phantomjs?

查看:59
本文介绍了整合maven/qunit/phantomjs的更好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been investigating the best way to do JS unit testing in our maven CI environment. What I currently have cobbled together is the following in my maven project:

  • qunit资源(JS/CSS文件)
  • 如果需要,qunit用html夹具测试html文件(每个被测文件一个)
  • 将测试html文件作为超链接的有序列表引用的index html文件
  • PhantomJS运行程序文件,其中:
    • 打开索引html文件并解析测试文件列表
    • 打开每个测试文件
    • 为每个文件拍摄qunit测试结果的屏幕截图
    • 如果有任何失败,请以状态"1"退出
    • 如果没有失败,请以状态"0"退出
    • qunit resources (JS/CSS files)
    • qunit test html files (one for each file under test) with html fixture if required
    • index html file which references the test html files as an ordered list of hyperlinks
    • PhantomJS runner file, which:
      • opens the index html file and parses out list of test files
      • opens each test file
      • takes a screenshot of the qunit test results for each file
      • If there are any failures, exit with a status of "1"
      • If there are no failures, exit with a status of "0"

      更改为pom.xml以在构建的测试阶段运行phantomjs测试:

      changes to pom.xml to run phantomjs tests during test phase of build:

      <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).这些测试在无头浏览器环境中运行,对qunit测试没有任何限制.我见过的其他maven/qunit集成由于在Rhino或其他JS环境中运行测试而受到限制,这些环境对我们可以编写的测试类型施加了限制.加上phantomjs,我们可以获取测试运行的屏幕截图,这有助于排除任何故障.

      So, this works nicely. It runs the qunit tests during builds on our dev and build machines (as long as PhantomJS is installed). The tests run in a headless browser environment with no restrictions on the qunit tests. Other maven/qunit integrations I've seen fall short due to running the tests in Rhino, or other JS environments which place restrictions on the type of tests we can write. Plus phantomjs gives us the ability to have the screenshots of the test runs, which are helpful in troubleshooting any failures.

      我的方法的缺点是在构建/开发计算机上需要PhantomJS安装.我不知道如何将phantomJS绑定到一个依赖项中,这样开发人员就不必担心安装PhantomJS.谁能朝这个方向推动我?我该如何开始?

      The drawback to my approach is that a PhantomJS installation is required on the build/dev machine. I don't know how to bundle phantomJS into a dependency such that developers don't need to worry about installing PhantomJS. Can anyone give me a push in this direction? How do I get started?

      推荐答案

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

      The phantomjs-maven-plugin provides an install goal for installing phantomjs so you don't need it pre-installed. After it installs phantomjs it sets a property with the path to the executable that other plugins can then use. It also has an exec goal for executing phantomjs scripts. Full disclosure: I wrote the plugin.

      这篇关于整合maven/qunit/phantomjs的更好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆