<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tea-Driven Development &#187; javascript</title>
	<atom:link href="http://blog.mattwynne.net/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mattwynne.net</link>
	<description>Matt Wynne taking it one tea at a time</description>
	<lastBuildDate>Tue, 10 Jan 2012 20:07:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Automating Javascript Unit Tests / Specs &#8211; Part 1</title>
		<link>http://blog.mattwynne.net/2008/04/06/automating-javascript-unit-tests-specs-part-1/</link>
		<comments>http://blog.mattwynne.net/2008/04/06/automating-javascript-unit-tests-specs-part-1/#comments</comments>
		<pubDate>Sun, 06 Apr 2008 05:39:42 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Agile / Lean Software Development]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.mattwynne.net/2008/04/06/automating-javascript-unit-tests-specs-part-1/</guid>
		<description><![CDATA[I&#8217;m building an Adobe Air application at the moment, which basically means loads of javascript development. We&#8217;re building it pure test-first, and have kicked off using jsUnit to get us started with something simple, flipping to the browser when we make a change and hitting the &#8216;run&#8217; button in the jsTest testrunner HTML page. I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m building an <a href="http://www.adobe.com/products/air/">Adobe Air</a> application at the moment, which basically means loads of javascript development.</p>

<p>We&#8217;re building it pure test-first, and have kicked off using <a href="http://www.jsunit.net/">jsUnit</a> to get us started with something simple, flipping to the browser when we make a change and hitting the &#8216;run&#8217; button in the jsTest testrunner HTML page.</p>

<p>I&#8217;m starting to find this quite unsatisfactory, however.</p>

<p><span id="more-46"></span></p>

<ul>
<li>Debugging when a test fails seems to be pretty much impossible using the testrunner page. There is a workaround where you put a line to call the failing test function into the fixture html file, then browse to that file, but that all feels like quite a rigmarole when you&#8217;re cooking on TDD gas.</li>
<li>All that alt-tabbing is making my thumb sore! I&#8217;m only writing scripts, so I should be able to get rapid feedback like you get with ruby / rails&#8217; <a href="http://www.zenspider.com/ZSS/Products/ZenTest/index.html#rsn">autotest</a> plug-in. Shouldn&#8217;t I?</li>
<li>Ultimately, I want to run these tests as part of an automated build process.</li>
</ul>

<p>It seems <a href="http://www.movesonrails.com/articles/trackback/231">I&#8217;m not alone</a> in having these goals.</p>

<p>Now jsUnit does have a java server which is built as an Ant task so you can automate the running of tests, so that could solve my automation goal, except we&#8217;re a .net shop using NAnt, and I can&#8217;t be bothered to get my head around configuring Ant just to run this one task right now.</p>

<p>I also notice from the sourceforge pages that jsUnit hasn&#8217;t been touched for a couple of years &#8211; version 2.2alpha, the latest release, was uploaded in March 2006.</p>

<p>There are a couple of alternative testing frameworks for javascript that could replace jsTest and make it all feel a bit more sexy.</p>

<ul>
<li><a href="http://mir.aculo.us/">Thomas Fuchs</a> <a href="http://wiki.script.aculo.us/scriptaculous/show/UnitTesting">has built one</a> that comes with his outstanding <a href="http://script.aculo.us/">script.aculo.us</a> library. The slides from a talk I saw him give at RailsConf London in 2006 are <a href="http://mir.aculo.us/stuff/AdventuresInJavaScriptTesting.pdf">here</a>.</li>
<li>There&#8217;s also <a href="http://jania.pe.kr/aw/moin.cgi/JSSpec">JSSpec</a> which looks pretty sweet.</li>
</ul>

<p>I has a look at JSSpec tonight, and knocked together a quick ruby script which uses the <a href="http://selenium.rubyforge.org/">selenium rubygem</a> to run a JSSpec test:</p>

<p><div>
<pre class="txt" style="font-family:monospace;">require 'rubygems'
require 'selenium'
require 'webrick'
&nbsp;
include WEBrick
&nbsp;
def go
    path_to_tests = '/Users/matt/Documents/projects/js-autotest/jsspec'
    port = 8001
    tests_url_base = &quot;http://localhost:#{port}/&quot;
&nbsp;
    server = create_web_server_at(path_to_tests, port)
    manager = start_selenium_service
    browser = start_selenium_browser_at(tests_url_base)
&nbsp;
    browser.open(tests_url_base + 'demo.html')
    puts &quot;page title is #{browser.get_title}&quot;
    # TODO - check that the specs passed!
&nbsp;
    puts 'stopping browser'
    browser.stop
&nbsp;
    puts 'stopping selenium service'
    manager.stop
&nbsp;
    puts 'stopping web server'
    server.stop    
end
&nbsp;
def start_selenium_browser_at(base_url)
    puts 'starting selenium browser'
    browser = Selenium::SeleniumDriver.new(&quot;localhost&quot;, 4444, &quot;*firefox&quot;, base_url, 15000)
    browser.start
    browser
end
&nbsp;
def start_selenium_service
    puts 'starting selenium service'
    manager = Selenium::ServerManager.new(Selenium::SeleniumServer.new)
    manager.start
    manager
end
&nbsp;
def create_web_server_at(path, port)
    puts &quot;starting web server on port #{port} at path_to_tests #{path}&quot;
    server = HTTPServer.new(
        <img src='http://blog.mattwynne.net/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ort            =&amp;gt; port,
        <img src='http://blog.mattwynne.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> ocumentRoot    =&amp;gt; path
    )
    trap(&quot;INT&quot;){ server.shutdown }
    t = Thread.new { server.start }
    server
end
&nbsp;
go</pre>
</div></p>

<p>It seems ridiculous to have to write a script that starts a web server, calls a framework that opens a browser that calls the web server that returns a page that runs the harness that runs my tests &#8211; surely there must be some shortcuts in there somewhere?!</p>

<p>I&#8217;ve considered trying to directly call one of the JavaScript engines from <a href="http://www.mozilla.org/js/spidermonkey/">Mozilla</a>, <a href="http://webkit.org/">Safari</a>, or the <a href="http://msdn2.microsoft.com/en-us/library/microsoft.jscript.aspx">.NET framework</a> but it&#8217;s not feeling right, and in any case, most of these test harnesses need use a whole HTML page, not just run javascripts.</p>

<p>I think my next step is to take another look at what Thomas Fuchs has been up to, and also <a href="http://drnicwilliams.com/2008/01/04/autotesting-javascript-in-rails/trackback/">this rails-based effort</a> from Dr Nic. We&#8217;re using the <a href="http://prototypejs.org/">prototype.js</a> framework anyway, so this seem like it would be a good fit, and his documentation suggests we should be able to automate it using rake, which should be fun.</p>

<p>Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattwynne.net/2008/04/06/automating-javascript-unit-tests-specs-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jsUnit vs jsUnit</title>
		<link>http://blog.mattwynne.net/2008/04/01/jsunit-vs-jsunit/</link>
		<comments>http://blog.mattwynne.net/2008/04/01/jsunit-vs-jsunit/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 20:33:02 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Agile / Lean Software Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://blog.mattwynne.net/2008/04/01/jsunit-vs-jsunit/</guid>
		<description><![CDATA[If, like me, you&#8217;ve been confused by the two different, identically-named, unit testing frameworks for javascript, here&#8217;s a very useful explanation of their strengths, weaknesses, and purposes.]]></description>
			<content:encoded><![CDATA[<p>If, like me, you&#8217;ve been confused by the <a href="http://www.jsunit.net/">two</a> <a href="http://jsunit.berlios.de/">different</a>, identically-named, unit testing frameworks for javascript, <a href="http://wiki.openqa.org/display/SRC/Selenium+RC+and+JsUnit">here&#8217;s a very useful explanation</a> of their strengths, weaknesses, and purposes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattwynne.net/2008/04/01/jsunit-vs-jsunit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

