‹ jan0sch.de

Javascript Unit Tests under TeamCity using JSTestDriver

2012-06-06

To write unit tests for your javascript code you can use a testing framework like JSTestDriver which is able to run under TeamCity.

Usage and configuration instructions for JSTestDriver are available on their website. For integration with TeamCity you’ll have to write an ant build file. But to be able to run browsers on your build agent machine you’ll have to use Xvfb. The test task in your ant file should look like the one below:

<target name="tests.javascript" depends="build.modules, build.all.artifacts">
  <property name="browsers" value="/usr/bin/firefox,/usr/bin/google-chrome"/>
  <exec executable="/usr/bin/xvfb-run">
    <arg line="java"/>
    <arg line="-jar /usr/local/share/jsTestDriver/JsTestDriver.jar"/>
    <arg line="--port 9876"/>
    <arg line="--config ${basedir}/Client/jsTestDriver.conf"/>
    <arg line="--browser ${browsers}"/>
    <arg line="--tests all"/>
    <arg line="--testOutput ${basedir}/Client/testOutput/"/>
  </exec>
</target>

Please adapt the paths and started browsers to your needs.