<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Rue marin</title>
	<atom:link href="http://ruemarin.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ruemarin.wordpress.com</link>
	<description>Web development and random things ...</description>
	<lastBuildDate>Thu, 10 Feb 2011 00:40:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ruemarin.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Rue marin</title>
		<link>http://ruemarin.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ruemarin.wordpress.com/osd.xml" title="Rue marin" />
	<atom:link rel='hub' href='http://ruemarin.wordpress.com/?pushpress=hub'/>
		<item>
		<title>WordPress.com Syntax Highlighter</title>
		<link>http://ruemarin.wordpress.com/2010/05/13/wordpress-com-syntax-highlighter/</link>
		<comments>http://ruemarin.wordpress.com/2010/05/13/wordpress-com-syntax-highlighter/#comments</comments>
		<pubDate>Thu, 13 May 2010 06:54:25 +0000</pubDate>
		<dc:creator>ruemarin</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://ruemarin.wordpress.com/?p=184</guid>
		<description><![CDATA[Since I blog about programming languages, I need to use a syntax highlighter to make the pieces of code more readable. All I found were WordPress plugins which are not allowed if you are a user of WordPress.com. Fortunately, I found this page: Posting Source Code Such a relief! All your need to do is to: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruemarin.wordpress.com&amp;blog=4954790&amp;post=184&amp;subd=ruemarin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Since I blog about programming languages, I need to use a syntax highlighter to make the pieces of code more readable.</p>
<p>All I found were WordPress plugins which are not allowed if you are a user of WordPress.com.</p>
<p>Fortunately, I found this page: <a title="Posting Souce Code on WordPress.com" href="http://en.support.wordpress.com/code/posting-source-code/" target="_blank">Posting Source Code</a></p>
<p>Such a relief! All your need to do is to:</p>
<ul>
<li>wrap your code with a wordpress element &#8220;<span style="font-family:Consolas, Monaco, 'Courier New', Courier, monospace;line-height:18px;font-size:12px;white-space:pre;">sourcecode&#8221;</span></li>
<li>provide some options such as the language (supports most popular programming languages: XML. HTML, JavaScript, C#, Ruby, Python, Java and many more!) and some formatting option</li>
</ul>
<p>Thank you again WordPress!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruemarin.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruemarin.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruemarin.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruemarin.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ruemarin.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ruemarin.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ruemarin.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ruemarin.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruemarin.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruemarin.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruemarin.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruemarin.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruemarin.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruemarin.wordpress.com/184/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruemarin.wordpress.com&amp;blog=4954790&amp;post=184&amp;subd=ruemarin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ruemarin.wordpress.com/2010/05/13/wordpress-com-syntax-highlighter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fdb8118b1dcd858424bb236a23a9f91?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ruemarin</media:title>
		</media:content>
	</item>
		<item>
		<title>Sitemesh + Velocity + Struts2</title>
		<link>http://ruemarin.wordpress.com/2010/01/27/struts2-velocity-sitemesh/</link>
		<comments>http://ruemarin.wordpress.com/2010/01/27/struts2-velocity-sitemesh/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 07:42:18 +0000</pubDate>
		<dc:creator>ruemarin</dc:creator>
				<category><![CDATA[Java + Web]]></category>
		<category><![CDATA[Sitemesh]]></category>
		<category><![CDATA[Struts2]]></category>
		<category><![CDATA[Velocity]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://ruemarin.wordpress.com/?p=162</guid>
		<description><![CDATA[The application I am currently working on uses Struts2 and Velocity. We recently implemented Sitemesh and while I applying it to our project, I was surprised by the very few posts across the web that talk about using Struts2, Velocity and Sitemesh. Maybe it is obvious to everyone else and I was just a bit [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruemarin.wordpress.com&amp;blog=4954790&amp;post=162&amp;subd=ruemarin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The application I am currently working on uses Struts2 and Velocity. We recently implemented Sitemesh and while I applying it to our project, I was surprised by the very few posts across the web that talk about using Struts2, Velocity and Sitemesh. Maybe it is obvious to everyone else and I was just a bit lost because I am new to Java web development and Struts2. Hopefully, this post will help you in using Sitemesh along with Velocity and Struts2.</p>
<h2>Sitemesh</h2>
<p>Sitemesh is a layout engine that will help developers to implement a consistent look and feel for their web applications. It will also facilitate the maintenance of the layout code. There are other frameworks that serve the same purpose and take a different approach. Among them, the most popular would be <a title="Tiles framework" href="http://tiles.apache.org/framework/index.html">Tiles framework</a>.  Tiles framework follows the composite pattern: in a very simplified explanation, each page will specifies which UI components (the top navigation, a left column or the footer) it needs in addition to the content of the page.  Sitemesh has a different approach and uses the decorator pattern. Each page is only concerned about what is specific to it. Before the page is sent back to the client, the framework applies a decorator that contains the UI components (top nav, left nav &#8230; ) common to your pages.  There are pros and cons of using either framework. What made me decide for Sitemesh is that if you need to change your layout, you&#8217;ll only have to make the change in your decorator while if you use Tiles, you&#8217;ll have to touch every pages. Also, something else that I like about Sitemesh is that you can have several decorators for the same application, meaning, you can apply a decorator for printing pages, or have 2 decorators, one implementing a newer layout and one keeping the current layout so users can choose which layout/style they like better.</p>
<h2>Installing Sitemesh</h2>
<ul>
<li><strong>dependency: </strong>Add the framework&#8217;s jar in your lib folder or via your pom.xml if you are using maven.</li>
<li>Create a decorator folder and drop there your decorator.xml</li>
<li>Update your web.xml file as follow:</li>
</ul>
<ol>
<li>Right before the Struts2Dispatch filter, drop the following:</li>
</ol>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;filter&gt;
    &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
    &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
&lt;/filter&gt;
&lt;filter&gt;
    &lt;filter-name&gt;struts-cleanup&lt;/filter-name&gt;
    &lt;filter-class&gt;org.apache.struts2.dispatcher.ActionContextCleanUp&lt;/filter-class&gt;
&lt;/filter&gt;
&lt;filter&gt;
    &lt;filter-name&gt;sitemesh&lt;/filter-name&gt;
    &lt;filter-class&gt;com.opensymphony.module.sitemesh.filter.PageFilter&lt;/filter-class&gt;
&lt;/filter&gt;
&lt;filter&gt;
    &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
    &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
&lt;/filter&gt;
&lt;filter&gt;
    &lt;filter-name&gt;struts-cleanup&lt;/filter-name&gt;
    &lt;filter-class&gt;org.apache.struts2.dispatcher.ActionContextCleanUp&lt;/filter-class&gt;
&lt;/filter&gt;
&lt;filter&gt;
    &lt;filter-name&gt;sitemesh&lt;/filter-name&gt;
    &lt;filter-class&gt;com.opensymphony.module.sitemesh.filter.PageFilter&lt;/filter-class&gt;
&lt;/filter&gt;
</pre></p>
<p>Then, in your servlet section, drop the following:</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;servlet&gt;
    &lt;servlet-name&gt;sitemesh-velocity&lt;/servlet-name&gt;
    &lt;servlet-class&gt;com.opensymphony.module.sitemesh.velocity.VelocityDecoratorServlet&lt;/servlet-class&gt;
    &lt;init-param&gt;
        &lt;param-name&gt;org.apache.velocity.toolbox&lt;/param-name&gt;
        &lt;param-value&gt;/WEB-INF/toolbox.xml&lt;/param-value&gt;
    &lt;/init-param&gt;
    &lt;init-param&gt;
        &lt;param-name&gt;org.apache.velocity.properties&lt;/param-name&gt;
        &lt;param-value&gt;/WEB-INF/config/base/velocitybase.properties&lt;/param-value&gt;
    &lt;/init-param&gt;
&lt;/servlet&gt;
</pre></p>
<p>There are a few things to understand from this configuration:</p>
<ol>
<li>The order of the filter matters.Sitemesh processing happen on top of Struts&#8217;s FileDispatcher. This implies you won&#8217;t have access to Struts objects in your decorators and files parsed in the decorators.</li>
<li>In the servlet section, if you are using Velocity, you need to specify 2 things: w<strong>here your toolbox.xml is and where your velocity macros are</strong>. You use for that the <strong>&lt;init-param&gt; </strong>element</li>
</ol>
<h2>Pitfalls</h2>
<ul>
<li>Sitemesh is layout engine, so use it for what it is for. Let&#8217;s say you created a decorator and need to access an object exposed by your controller, well, you don&#8217;t have access to this object anymore since Sitemesh processing is happening after Struts2&#8242;s in the response. You can extend the Sitemesh filter and put your objects in the context but I found that it&#8217;s best to stay away from deep changes and keep your design as simple as possible. Simple is good, it makes it easy to maintain code and often, engineers tend to over engineer a solution.</li>
<li>AJAX responses will get decorated so exclude the AJAX URLs in the decorators.xml file using the exclude element.</li>
<li>the Sitemesh version you need depends on the version of Struts2 you are using</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruemarin.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruemarin.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruemarin.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruemarin.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ruemarin.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ruemarin.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ruemarin.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ruemarin.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruemarin.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruemarin.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruemarin.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruemarin.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruemarin.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruemarin.wordpress.com/162/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruemarin.wordpress.com&amp;blog=4954790&amp;post=162&amp;subd=ruemarin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ruemarin.wordpress.com/2010/01/27/struts2-velocity-sitemesh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fdb8118b1dcd858424bb236a23a9f91?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ruemarin</media:title>
		</media:content>
	</item>
		<item>
		<title>Writing unit testable JavaScript code</title>
		<link>http://ruemarin.wordpress.com/2009/12/11/writing-unit-testable-javascript-code/</link>
		<comments>http://ruemarin.wordpress.com/2009/12/11/writing-unit-testable-javascript-code/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 08:35:54 +0000</pubDate>
		<dc:creator>ruemarin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Maintainable JavaScript]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://ruemarin.wordpress.com/?p=149</guid>
		<description><![CDATA[Today&#8217;s web applications heavily use JavaScript to enrich their User Interface. As we rely on JavaScript to accomplish more and more demanding features, it becomes necessary to apply engineering practices to JavaScript and consider it as a legitimate programming language. I recently blogged about a JavaScript testing framework called JsTestDriver. But it would be useless [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruemarin.wordpress.com&amp;blog=4954790&amp;post=149&amp;subd=ruemarin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s web applications heavily use JavaScript to enrich their User Interface. As we rely on JavaScript to accomplish more and more demanding features, it becomes necessary to apply engineering practices to JavaScript and consider it as a legitimate programming language.</p>
<p>I recently blogged about a JavaScript testing framework called <a title="JsTestDriver introduction" href="http://ruemarin.wordpress.com/2009/12/01/jstestdriver/">JsTestDriver</a>. But it would be useless if I cannot write JavaScript code that is <strong>unit testable</strong><strong> </strong> to leverage my testing framework. A benefit of writing unit testable code is that it will also help you to <strong>write maintainable code</strong>.</p>
<p>Before going any further, I would like to briefly set a common ground on those 2 notions.</p>
<h2>Unit testing</h2>
<p>There are several kind of testing that can be performed to ensure a product&#8217;s quality:</p>
<ul>
<li><strong>Unit testing</strong>: test the smallest unit of your code. The goal is to ensure that all methods of your objects works correctly, independently from other objects. There are many unit test framework available such as QUnit, <a title="JsTestDriver introduction" href="http://ruemarin.wordpress.com/2009/12/01/jstestdriver/">JsTestDriver that I highly recommand</a>.</li>
<li><strong>Integration testing</strong>: test the interaction/integration between your objects. <a title="Selenium web application testing tool" href="http://seleniumhq.org/">Selenium</a> is a popular integration testing tool.</li>
<li><strong>Functional testing</strong>: test your use cases which could be a serie of steps executed by the user.</li>
</ul>
<p>Writing unit testing will:</p>
<ul>
<li> allow you to <strong>verify if a code change breaks or not you code</strong>.</li>
<li><strong>improve the quality of your code</strong>. A good practice is to write your code first. It can be strange at first but it will force you to break your implementation into small, independent chunks of code that serve 1 goal. Because your code is broken down, it is easier to see duplicate code, clearer to understand the purpose of each method.</li>
<li>because you broke down your code in small pieces, the method should be as simple as it gets and therefore be <strong>self documenting</strong></li>
</ul>
<p>As you can see, I did not say that your application will be bug free. Why not? First of all, software specifications can be incomplete or incorrect. You could be missing certain use cases. Secondly, unit testing ensures that your objects work correctly but outside of the application context, independently from other objects. For more on unit testing in JavaScript, please refer to <a title="test driven development" href="http://video.yahoo.com/watch/3737228/10267335">Nicholas C. Zakas&#8217;s video on test driven development</a>.</p>
<p>As a note, it is important when writing unit tests to keep in mind the goals to be achieved, i.e writing tests against unit of your code. Writing bad unit tests can be costly to maintain because you&#8217;ll end writing and maintaining unit tests with low value. See the very interesting post <a title="Writing Unit Test: Best and Worse Practices" href="http://blog.codeville.net/2009/08/24/writing-great-unit-tests-best-and-worst-practises/">Writing Unit Test: Best and Worse Practices</a> for more information on that topic.</p>
<h2>Maintainable code</h2>
<p>What is maintainable code? Maintainable code is code that is:</p>
<ul>
<li>Understandable</li>
<li>Intuitive</li>
<li>Adaptable</li>
<li>Extendable</li>
<li>Debuggable/Testable</li>
</ul>
<p>If you would like to learn more information on writing maintainable JavaScript code, please refer to this excellent video from <a title="Maintainable JavaScript" href="http://video.yahoo.com/watch/568351/2820297">Nicholas Zakas &#8211; Maintainable JavaScript.</a></p>
<p>In his video, N. Zakas lists several elements that will help you to write maintainable code such as code convention, separation of concerns, coding practices &#8230; In today&#8217;s post, I just want to briefly talk about writing testable code.</p>
<h2>Let&#8217;s get started</h2>
<p>For the context, we will imagine we want to implement a calculator with 2 input fields and 2 buttons to perform basic operations (+ and -) and a label to display the result. How would you write testable JavaScript code for such as feature? It can seem strange since it is bound to the UI. In other programming languages such as Java, C#, PHP, Ruby &#8230; you are dealing with objects and testing their methods. Well, let&#8217;s do the same!</p>
<p>There are many ways to achieve today&#8217;s goal but they all converge towards the same idea. You first need to visualize this feature as a module. This module has a state (values of the inputs), operations and event handlers bound to the buttons.</p>
<p>I am going to write the code first and explain afterwards:</p>
<p><pre class="brush: jscript;">
var calculator = {
	value_1:0,
	value_2:0,
	config: {
		labelSelector:&quot;#resultLabel&quot;
	},
	/* Add event handlers to the buttons */
	init:function(){
		$(&quot;#add_button&quot;).bind(&quot;click&quot;, function(){
			this.value_1 = $(&quot;#input1&quot;).val();
			this.value_2 = $(&quot;#input2&quot;).val();
			this.add();
		});
		$(&quot;#substract_button&quot;).bind(&quot;click&quot;, function(){
			this.value_1 = $(&quot;#input1&quot;).val();
			this.value_2 = $(&quot;#input2&quot;).val();
			this.substract();
		});
	},

	/* Some comments for the add function */
	add:function(){
		var result = this.value_1 + this.value_2;
		this.displayResult(result);
	},

	/* Some comments for the substract function */
	substract(){
		var result = this.value_1 - this.value_2;
		this.displayResult(result);
	},

	/* Some comments for the display function */
	displayResult:function(value){
		$(this.config.labelSelector).text(value);
	}
};
</pre></p>
<h2>Explanations</h2>
<ol>
<li>I created an object (in this case, an object literal) that encapsulates my properties and my methods.</li>
<li>When the DOM is ready, we will initialize the object as follow: <em>calcultator.init();. </em>The <em>init() </em>method attaches the event handlers to the buttons. It is a nice approach because by reading the init() method, I know what the module is going to do without having to look at the implementation details.</li>
<li>We implement the functions called in the event handlers. This is a good approach because we do not mix event handlers and business logic. Say we want to change the event on which we perform an <em>&#8216;add&#8217;</em>, we just need to change the trigger event but we can leave the add method untouched.</li>
<li>Even if this is a simple example, I kept in mind the idea of keeping the method to serve 1 testable purpose. When writing unit tests, I can easily call my add method and test it against an expected value.</li>
<li>I created a displayResult that is being called in both my add and substract mehotds so I can test it and I do not repeat the display logic in the add nor the substract method.</li>
</ol>
<h2>Thoughts</h2>
<p>Did we write maintainable code?</p>
<ul>
<li>Understandable: the logic is separated in small units of code making it easy understand and we commented each functions.</li>
<li>Intuitive: the init method explains quickly what the module does</li>
<li>Adaptable: if needed, we can easily change the triggering events of the add or the substract method actions</li>
<li>Extendable: if is easy to add a new feature such as multiply or divide by adding a new event handler and a new function</li>
<li>Debuggable/Testable: code is splitted in unit testable code</li>
</ul>
<p>Of course, it is a very simplistic example and I do not drill down into details. For example, to improve the code above, you will still have to write:</p>
<ol>
<li>exception handling</li>
<li>comment (unintuitive) code</li>
<li>write your unit tests</li>
</ol>
<p>The list of possible improvement is far beyond the scope of this post. <strong>What I wanted to share is the pattern to use when writing modular JavaScript</strong>:</p>
<ul>
<li>encapsulating you module&#8217;s behavior in a object</li>
<li>using an init() method</li>
<li>separating event handling from business logic</li>
<li>I am obviously using jQuery library. My recommendation is to avoid as much as possible to refer to CSS selectors in your functions. You can put them in a config object property like I did for the label selector. It is up to you. The advantage is that is you decide to change your markup, your changes in your JS code will be minimal.</li>
</ul>
<p>Last but not least, <strong>run your tests on all browsers</strong>. Even if you use a library that is cross browser libraries such as jQuery to implement events &#8230; there are still differences in the behavior of browsers when it comes to run JS code (and differences of performance as well!).</p>
<p>I hope you enjoyed this post and that it gave you some ideas on how to write testable and maintainable code!</p>
<p>Thanks for reading.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruemarin.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruemarin.wordpress.com/149/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruemarin.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruemarin.wordpress.com/149/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ruemarin.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ruemarin.wordpress.com/149/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ruemarin.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ruemarin.wordpress.com/149/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruemarin.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruemarin.wordpress.com/149/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruemarin.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruemarin.wordpress.com/149/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruemarin.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruemarin.wordpress.com/149/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruemarin.wordpress.com&amp;blog=4954790&amp;post=149&amp;subd=ruemarin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ruemarin.wordpress.com/2009/12/11/writing-unit-testable-javascript-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fdb8118b1dcd858424bb236a23a9f91?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ruemarin</media:title>
		</media:content>
	</item>
		<item>
		<title>JsTestDriver</title>
		<link>http://ruemarin.wordpress.com/2009/12/01/jstestdriver/</link>
		<comments>http://ruemarin.wordpress.com/2009/12/01/jstestdriver/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 06:53:52 +0000</pubDate>
		<dc:creator>ruemarin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[JavaScript Unit Testing]]></category>

		<guid isPermaLink="false">http://ruemarin.wordpress.com/?p=146</guid>
		<description><![CDATA[JavaScript Unit Testing and Continuous Integration with JsTestDriver I am currently reworking the JavaScript layer of an application at work. Among several initiatives to improve the maintainability of the app, I suggested to adopt JavaScript unit testing. There are several JavaScript unit testing framework out there. The one that I used before was QUnit, a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruemarin.wordpress.com&amp;blog=4954790&amp;post=146&amp;subd=ruemarin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>JavaScript Unit Testing and Continuous Integration with JsTestDriver</h1>
<p>I am currently reworking the JavaScript layer of an application at work. Among several initiatives to improve the maintainability of the app, I suggested to adopt JavaScript unit testing. There are several JavaScript unit testing framework out there. The one that I used before was <a title="QUnit" href="http://docs.jquery.com/QUnit">QUnit</a>, a simple unit test framework developed by the jQuery team and I intended to use it again.</p>
<p>The final goal was to have our tests ran within our continuous integration process, meaning the JS tests would run when a build was scheduled.</p>
<p>My initial approach was to write:</p>
<ol>
<li>QUnit tests and called the script from a single file.</li>
<li>Generate an automated test with Selenium to read the result section of the QUnit result page</li>
<li>Depending on what was read, fail or pass the test like any other JUnit tests.</li>
</ol>
<p>Simple enough until a coworker briefly mentioned to me <a href="http://code.google.com/p/js-test-driver/">JsTestDriver</a>.</p>
<h2>What is JsTestDriver?</h2>
<p>JsTestDriver is a JavaScript testing framework supported by Google. It is more complete than a JavaScript Unit Testing library and can provide you with the following benefits:</p>
<ul>
<li><strong>provides JavaScript Testing API</strong> similar to JUnit. You can also write tests against the DOM very easily.</li>
<li> <strong>can be run via the command line</strong>: this means it can be integrated to your Continuous Integration process.</li>
<li> <strong>can output test results in the same XML format as JUnit results tests</strong>: this will allow you to produce reports on the last build and run of tests suites.</li>
<li>can provide <strong>code coverage</strong>.</li>
<li>has an eclipse plug-in to run the tests. The plugin is very enjoyable to use because you <strong>can run your tests against any browser you specify without leaving leaving Eclipse.</strong> With QUnit, you would have to open each browser and refresh the page every time you make a code change for each browser you test against.</li>
<li>last but not least, it exists adapters for other JS testing framework so that<strong> you can run your tests using JsTestDriver even if you used another testing library such as QUnit</strong>.</li>
</ul>
<p>As you can see, JsTestDriver and its plugins offer a much more complete set of tools to write and automate JS testing.</p>
<p>I was somewhat reluctant at switching from QUnit (which I thought was good enough) to JsTestDriver. However I realized QUnit was only a part (but essential nonetheless) of the whole JS testing process.</p>
<h2>Where to I get started?</h2>
<p>I will not write today a tutorial on using JsTestDriver, maybe later. I will just point out the resources to get a better feel for it.</p>
<p>1. A presentation video: <a href="http://www.youtube.com/watch?v=aDKGGZv-T4M">http://www.youtube.com/watch?v=aDKGGZv-T4M</a></p>
<p>2. The google code website: <a href="http://code.google.com/p/js-test-driver/">http://code.google.com/p/js-test-driver/</a></p>
<p>To break down the jsTestDriver site and I am linking each of the above points (in the what is JsTestDriver section) to its corresponding page for more info.</p>
<ul>
<li><a title="TestCase" href="http://code.google.com/p/js-test-driver/wiki/TestCase">JavaScript Testing API</a> (API and how to write a test) &#8211; <a href="http://code.google.com/p/js-test-driver/wiki/HtmlDoc">To add HTML to your tests</a></li>
<li><a href="http://code.google.com/p/js-test-driver/wiki/CommandLineFlags">How to run from the command line and the list of options</a></li>
<li><a title="Continuous build" href="http://code.google.com/p/js-test-driver/wiki/ContinuousBuild">Using the proper options will allow you to output an XML that can be used for build reports</a> (see what has failed and where)</li>
<li><a title="Test coverage" href="http://code.google.com/p/js-test-driver/wiki/CodeCoverage">How to obtain test coverage</a></li>
<li><a href="http://code.google.com/p/js-test-driver/wiki/UsingTheEclipsePlugin">Eclipse plugin</a></li>
<li><a href="http://code.google.com/p/js-test-driver/wiki/QUnitAdapter">QUnit adapter</a></li>
</ul>
<p>There are a few other topics such as how to debug (which is the same as you would debug a JS script with Firebug) and the config file (very simple).</p>
<p>I hope this gave you an idea of JsTestDriver. Hopefully I will post an example soon.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruemarin.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruemarin.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruemarin.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruemarin.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ruemarin.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ruemarin.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ruemarin.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ruemarin.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruemarin.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruemarin.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruemarin.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruemarin.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruemarin.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruemarin.wordpress.com/146/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruemarin.wordpress.com&amp;blog=4954790&amp;post=146&amp;subd=ruemarin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ruemarin.wordpress.com/2009/12/01/jstestdriver/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fdb8118b1dcd858424bb236a23a9f91?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ruemarin</media:title>
		</media:content>
	</item>
		<item>
		<title>HTML Elements Display: Block, Inline and None</title>
		<link>http://ruemarin.wordpress.com/2009/10/11/html-elements-display-block-inline-and-none/</link>
		<comments>http://ruemarin.wordpress.com/2009/10/11/html-elements-display-block-inline-and-none/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 19:31:18 +0000</pubDate>
		<dc:creator>ruemarin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://ruemarin.wordpress.com/?p=122</guid>
		<description><![CDATA[There are 3 ways HTML elements can be displayed: as a block inline not being displayed Note: for the list of block and inline elements, refer to my short post here. Block Elements Behavior Block elements (for example: div, p, table, address) will span over the whole width that is available to them and the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruemarin.wordpress.com&amp;blog=4954790&amp;post=122&amp;subd=ruemarin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are 3 ways HTML elements can be displayed:</p>
<ul>
<li>as a block</li>
<li>inline</li>
<li>not being displayed</li>
</ul>
<p>Note: for the list of block and inline elements, refer to my short post <a title="Semantic HTML" href="http://ruemarin.wordpress.com/2009/10/11/semantic-html/">here</a>.</p>
<h1>Block Elements Behavior</h1>
<p>Block elements (for example: div, p, table, address) will span over the whole width that is available to them and the next element will display in the following line.</p>
<h1>Inline Elements Behavior</h1>
<p>Inline elements will just take the space they need for their content. Example of inline elements are span, a, cite, em, strong.</p>
<h1>So what now?</h1>
<p>Well, first of all, if you know whether your element is a block or an inline elements, you know how wide it is going to be.</p>
<p>Second, you should control the width of block elements, not inline elements.</p>
<p>Third, you can alter the behavior via CSS displaying block elements as inline (display: inline-block) or vice versa, display inline elements as block (display: block).</p>
<p>Note: watch out for browser support.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruemarin.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruemarin.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruemarin.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruemarin.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ruemarin.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ruemarin.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ruemarin.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ruemarin.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruemarin.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruemarin.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruemarin.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruemarin.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruemarin.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruemarin.wordpress.com/122/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruemarin.wordpress.com&amp;blog=4954790&amp;post=122&amp;subd=ruemarin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ruemarin.wordpress.com/2009/10/11/html-elements-display-block-inline-and-none/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fdb8118b1dcd858424bb236a23a9f91?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ruemarin</media:title>
		</media:content>
	</item>
		<item>
		<title>Semantic HTML</title>
		<link>http://ruemarin.wordpress.com/2009/10/11/semantic-html/</link>
		<comments>http://ruemarin.wordpress.com/2009/10/11/semantic-html/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 19:02:46 +0000</pubDate>
		<dc:creator>ruemarin</dc:creator>
				<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://ruemarin.wordpress.com/?p=118</guid>
		<description><![CDATA[Today, I wanted to list the semantic HTML tags as a reference for myself. Writting semantic HTML is definitively a Web Development best practice. Writting semantic HTML means using meaningful HTML elements in order to better describe and organize the content of the page. This practice has several major benefits: Improve the Search Engine Optimization [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruemarin.wordpress.com&amp;blog=4954790&amp;post=118&amp;subd=ruemarin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today, I wanted to list the semantic HTML tags as a reference for myself.</p>
<p>Writting semantic HTML is definitively a Web Development best practice. Writting semantic HTML means using meaningful HTML elements in order to better describe and organize the content of the page.</p>
<p>This practice has several major benefits:</p>
<ol>
<li>Improve the Search Engine Optimization of your pages: By using meaningful HTML elements, web crawlers better understand your pages&#8217; content and therefore, index it appropriately according to your site&#8217;s subject.</li>
<li>Accessibility: Your content will be accessed mainly via a web browser but chances are that it will also be accessed via other devices like mobile devices.</li>
<li>Maintenance of the pages: Using semantic markup makes the code easier to read for machines (crawlers) and humans. Web Developers will better understand a page using meaningful HTML elements (if they know those elements) and will avoid to use unnecessary, meaningless div elements making the page harder to style (CSS) or interact with JavaScript.</li>
</ol>
<h2>Document structure elements</h2>
<pre>html, head, body
</pre>
<h2><strong>Document Head Elements</strong></h2>
<pre>link, meta, object, script, style and title
</pre>
<h2>Document Body Elements</h2>
<pre><strong>Block Elements (text)</strong>: p, h1, h2, h3, h4, h5, h6
<strong>Block Elements (list)</strong>: dl, dt, dd, ol, ul, li
<strong>Block Elements (other)</strong>: address, blockquote, del, div, hr, ins, pre, noscript, script
<strong>
Inline Elements</strong>
Note: Inline elements must be nested in a block element
a, abbr, acronym, dfn, em, strong, code, sample, span, br, cite, del, ins, q, sub

<strong>Form Elements:</strong> form, button, input, label, legend, fieldset, option, optgroup. textarea, select

<strong>Tables</strong>: table, thead, tbody, tfoot, tr, th, td, colgroup, col, caption
</pre>
<p>I think a web developer should know at least 90% of those tags, their meaning and how to use them.</p>
<p>Reference: <a title="HTML Wiki Reference" href="http://en.wikipedia.org/wiki/HTML">http://en.wikipedia.org/wiki/HTML</a> ||<a title="Semantic HTML" href="http://en.wikipedia.org/wiki/HTML#Semantic_HTML"> http://en.wikipedia.org/wiki/HTML#Semantic_HTML</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruemarin.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruemarin.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruemarin.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruemarin.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ruemarin.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ruemarin.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ruemarin.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ruemarin.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruemarin.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruemarin.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruemarin.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruemarin.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruemarin.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruemarin.wordpress.com/118/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruemarin.wordpress.com&amp;blog=4954790&amp;post=118&amp;subd=ruemarin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ruemarin.wordpress.com/2009/10/11/semantic-html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fdb8118b1dcd858424bb236a23a9f91?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ruemarin</media:title>
		</media:content>
	</item>
	</channel>
</rss>
