I am looking for testing tools for Javascript and reached at This Stackoverflow page.
The page contains bunch of useful information :)
After reading the page, I decided to use JsTestDriver for the following reason.
Ok now you need to run client side (actual tests) against the server. You will use FireFox + Xvfb or PhantomJS as headless browser.
Also jsTestDriver.conf should something like this:
I ran tests and almost everything worked fine exept one thing.... On my env, somehow browser used for the tests does not exit properly. One of the errors I have gotten:
To avoid this, I wrote a shell script for starting up and shuting down JsTestDriver server. And starting up the server before running tests and shutting down the server after running tests.
I know this is a bit silly solution. Ideally JsTestDriver server should keep running. However this is enough for me now.... Luckly the JsTestDriver server is very light, so it doesn't take a long time for starting up. Here is my bash shell script.
The page contains bunch of useful information :)
After reading the page, I decided to use JsTestDriver for the following reason.
- having high affinity with CI server
- providing plugin for codecoverage - (lcov format)
- JUnit format report
java -jar JsTestDriver-1.3.4.b.jar --port 9876One thing you should be careful about is if you run the above command in the directory which includes jsTesDriver.conf, the jar automatically picked up the jsTestDriver.conf and and it starts as server mode.
Ok now you need to run client side (actual tests) against the server. You will use FireFox + Xvfb or PhantomJS as headless browser.
java -jar JsTestDriver-1.3.4.b.jar --browser {path to browser} --tests all --config jsTestDriver.conf --testOutput testResult
Also jsTestDriver.conf should something like this:
server: http://localhost:9876 load: # javascript source (test target) - js/jquery/jquery-1.6.4.min.js - js/mine/*.js # javascript for test cases - test/*.js exclude: - ../web/js/unused.js plugin: - name: "coverage" jar: "jstestdriver/plugins/coverage-1.3.4.b.jar" module: "com.google.jstestdriver.coverage.CoverageModule"
I ran tests and almost everything worked fine exept one thing.... On my env, somehow browser used for the tests does not exit properly. One of the errors I have gotten:
Failures during test run. Caused by: com.google.jstestdriver.browser.BrowserPanicException: Browser Firefox 10.0.5 Linux During {"browserInfo":{"id":1342485894780,"name":"Firefox","version":"XX.X.X","os":"Linux","uploadSize":50,"serverReceivedHeartbeat":true,"ready":true},"cause":"Browser unresponsive since 2012-07-17T00:45:08.058Z during null"} at com.google.jstestdriver.CommandTask.run(CommandTask.java:136) at com.google.jstestdriver.JsTestDriverClientImpl.sendCommand(JsTestDriverClientImpl.java:103) at com.google.jstestdriver.JsTestDriverClientImpl.runTests(JsTestDriverClientImpl.java:141) at com.google.jstestdriver.JsTestDriverClientImpl.runAllTests(JsTestDriverClientImpl.java:120) at com.google.jstestdriver.RunTestsAction.run(RunTestsAction.java:69) at com.google.jstestdriver.browser.BrowserActionRunner.call(BrowserActionRunner.java:70) at com.google.jstestdriver.browser.BrowserActionRunner.call(BrowserActionRunner.java:37) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) at com.google.jstestdriver.browser.BrowserActionExecutorAction.run(BrowserActionExecutorAction.java:154) at com.google.jstestdriver.ActionRunner.runActions(ActionRunner.java:81) at com.google.jstestdriver.embedded.JsTestDriverImpl.runConfigurationWithFlags(JsTestDriverImpl.java:342) at com.google.jstestdriver.embedded.JsTestDriverImpl.runConfiguration(JsTestDriverImpl.java:233) at com.google.jstestdriver.Main.main(Main.java:70) Caused by: com.google.jstestdriver.browser.BrowserPanicException: Browser Firefox XX.X.X Linux During {"browserInfo":{"id":1342485894780,"name":"Firefox","version":"XX.X.X","os":"Linux","uploadSize":50,"serverReceivedHeartbeat":true,"ready":true},"cause":"Browser unresponsive since 2012-07-17T00:45:08.058Z during null"} Unexpected Runner Condition: Failures during test run. Use --runnerMode DEBUG for more information.
To avoid this, I wrote a shell script for starting up and shuting down JsTestDriver server. And starting up the server before running tests and shutting down the server after running tests.
I know this is a bit silly solution. Ideally JsTestDriver server should keep running. However this is enough for me now.... Luckly the JsTestDriver server is very light, so it doesn't take a long time for starting up. Here is my bash shell script.
#!/bin/bash JsTestDriverJar=/home/jenkins/JsTestDriver/JsTestDriver-1.3.4.b.jar JsTestDriverPIDFile=/home/jenkins/JsTestDriver/JsTestDriver.pid PORT=9876 start(){ java -jar $JsTestDriverJar --port $PORT --runnerMode QUIET >& /dev/null & echo $! > $JsTestDriverPIDFile } stop(){ if [ -f $JsTestDriverPIDFile ] then PID=$(cat $JsTestDriverPIDFile) kill -9 $PID #> /dev/null 2>&1 JS_TEST_DRIVER_KILLOUT=$? if [ $JS_TEST_DRIVER_KILLOUT -ne 0 ] then echo "Failed to kill: see messages above if exists" else echo "Successfully killed" echo "Removing PID file... $JsTestDriverPIDFile" rm -f $JsTestDriverPIDFile fi else echo "Looks no PID file... $JsTestDriverPIDFile" fi } status(){ PID=$(cat $JsTestDriverPIDFile) ps -p $PID } case "$1" in start) start ;; stop) stop ;; status) status ;; *) echo "Usage: JsTestDriver {start|stop|status}" exit 1 ;; esac exit $?
コメント