Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Jasmine with JS-Test-Driver

7,409 views

Published on

Explored various java-script test-runners, which are capable of supporting JS tests on major browsers, of which JS-Test-Driver stands the most promising...

Published in: Technology

Jasmine with JS-Test-Driver

  1. 1. Problem Statement / Target<br />Ability to run JavaScript tests through commandline (not exactly headlessly)<br />Integrate test results with the Bamboo build plan<br />Visibility of code-coverage<br />
  2. 2. Options for JS test-runner tools<br />Env.js and Rhino.js<br />V8 JavaScript Engine<br />Jasmine-Maven plug-in<br />Jasmine-Ruby plug-in<br />Jasmine-JsTestDriver<br />
  3. 3. Env.js & Rhino.js<br />Uses its own JS engine<br />Is more closer to Mozilla Firefox<br />Still does not even behave as a mirror image of Firefox, on commandline<br />Findings: behaves as a different browser in itself<br />V8 JavaScript Engine<br />Google's open source JavaScript engine, used in chrome<br />Is a C++ code-base, needs to be compiled on local machine<br />Pretty capable, supports Mozilla and chrome, not sure about Safari<br />Findings: Pretty capable, but have not explored much<br />
  4. 4. Jasmine-Maven Plug-in<br />Uses HTMLUnit for headless browser runner<br />HTMLUnit’s only supports Firefox and IE<br />Findings – not capable to mock Safari capabilities<br />Jasmine-Ruby Plug-in<br />Has major issues with the “afterEach” and “toContains” Jasmine capabilities<br />Can run with any browser – need to open the SpecRunner.html on the browser of choice !!!<br />Findings – Promising, but needs to evolve<br />
  5. 5. JsTestDriver<br />
  6. 6. Why JsTestDriver<br />Can run JS tests through commandline, on the browser(ant version) of choice<br />Generates output in JUnit format, making it easier for Bamboo integration<br />Well compatible with Jasmine<br />Possesses code-coverage capability<br />Had certain minor issues, which have a workaround now<br />
  7. 7. Workarounds required for JTD<br />Not fully compatible with prototype.js – required jar fix<br />Jasmine spy issue, was unable to remove the spies – required Jasmine-JsTestDriver Adapter fix<br />Never closes the browser tab when test-runner completes – added a minor apple-script fix<br />
  8. 8. Testing with JTD<br />jsTestDriver configuration<br />server: http://localhost:9876<br />load:<br /> - "tools/jasmine-test-driver/jasmine-1.0.1.js"<br /> - "tools/jasmine-test-driver/JasmineAdapter.js"<br /> - "tools/jasmine-test-driver/prototype-1.6.0.3.js"<br /> - "dist/qowt-browser-unitTests.js"<br />rake test<br />java -Xms512m -Xmx1024m <br />-jar tools/jasmine-test-driver/JsTestDriver-1.2.2.jar <br />--reset <br />--port 9876 <br />--runnerMode DEBUG <br />--browser open <br />--tests all <br />--testOutput tests/test-reports<br />
  9. 9. Creating test-append-area<br />QOWT.TEST.UTILS = function() {<br /> return {<br /> /**<br /> * creates dummy Test Append Area, and appends it to the document object, for running tests headlessly<br /> * While executing tests on Sumulat, you get "testAppendArea" div present in the html body itself.<br /> * But, in case of jsTestDriver, you do not have any such div present, and will have to create it on the fly.<br /> * @return testAppendArea div <br /> */<br />createTestAppendArea: function() {<br />vartestAppendAreaContainer = document.getElementById('testAppendArea');<br /> if(testAppendAreaContainer === null) {<br />testAppendAreaContainer = document.createElement("div");<br />testAppendAreaContainer.innerHTML = '<div id="testAppendArea"></div>';<br />document.body.insert(testAppendAreaContainer);<br /> }<br /> return document.getElementById('testAppendArea');<br /> }<br /> };<br />}();<br />USAGE: (CommonContentMrg-test.js)<br />testAppendArea = QOWT.TEST.UTILS.createTestAppendArea();<br />testAppendArea.appendChild(rootNode);<br />
  10. 10. Code-Coverage with JTD<br />rake coverage<br />http://quicknet/display/PROD/Generating+Code+Coverage+Reports<br />Coverage configurations<br />server: http://localhost:9876<br />load:<br /> - "../jasmine-1.0.1.js"<br /> - "../JasmineAdapter.js"<br /> - "../prototype-1.6.0.3.js"<br /> - "../../../dist/qowt-browser-doc-sheet.js"<br /> - "../../../dist/qowt-browser-point.js"<br /> - "../../../dist/qowt-browser-testsOnly.js"<br />plugin:<br /> - name: "coverage"<br /> jar: "tools/jasmine-test-driver/plugins/coverage-1.2.2.jar"<br /> module: "com.google.jstestdriver.coverage.CoverageModule"<br />
  11. 11. Debugging on JTD<br />Start the server - java -Xms512m -Xmx1024m -jar tools/jasmine-test-driver/JsTestDriver-1.2.2.jar --port 9876<br />Open the browser with the url- http://localhost:9876/capture<br />Run the tests - java -Xms512m -Xmx1024m -jar tools/jasmine-test-driver/JsTestDriver-1.2.2.jar --tests all<br />Apply the breakpoint<br />Run the tests again<br />
  12. 12. Known issue with JTD<br />The rake script fails to close Safari window, if it has the developer console opened !!! <br />
  13. 13. Questions … ?<br />

×