I would like to use unit testing for JavaScript in TeamCity.
I am using QUnit, and I have seen a couple of places that suggest using phantomjs and QUnitTeamCityDriver. I just have not been able to get it to work…
I don’t have a lot of experience in this, and can’t seem to even get phantomjs to run unit tests in command line.
I literally copied the example from QUnitTeamCityDriver: simple_test.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>QUnit Example</title>
<link rel="stylesheet" href="test_tools/qunit-1.10.0.css">
<script type="text/javascript" src="resources/jquery-1.8.1.js"></script>
<script type="text/javascript" src="test_tools/qunit-1.10.0.js"></script>
<script type="text/javascript" src="qunit_teamcity_driver/QUnitTeamCityDriver.js"></script>
<script type="text/javascript" src="tests.js"></script>
</head>
<body>
<div id="qunit"></div>
<h1 id="qunit-header">QUnit example</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div>
</body>
</html>
tests.js has some simple tests that work or not, if I try it with the simple_test.html.
The other referenced files, in the html, are in the respective folders, of course.
phantomjs.exe, tests.js and simple_test.html are in the root of the directory I am calling from.
The directions for TeamCity build are:
Add a "Command Line" Build Step to your build in TeamCity which executes Tests.htm via PhantomJS
Command executable: C:\PhamtomJS\phantomjs.exe
Command parameters: \Scripts\QUnitTeamCityDriver.phantom.js Tests.htm
(which doesn’t work, so I want to test on actual command line before putting in the command line inside TeamCity)
Some things I have tried:
phantomjs.exe tests.js
phantomjs.exe tests.js simple_test.html
phantomjs.exe simple_test.html
phantomjs.exe test_tools\qunit-1.10.0.js tests.js simple_test.html
phantomjs.exe qunit_teamcity_driver/QUnitTeamCityDriver.phantom.js simple_test.html
result: either Parse error or Can’t find variable: test
Please, can someone point me in the right direction, give me an example, tell me what I am doing wrong ? Thank you very much.
If your technology stack is a match I’ve had success using Chutzpah.
Among other things it does the heavy lifting for you by dealing with the calls to and from phantomjs described by kabaros, as well as providing TeamCity and Visual Studio integration.