<?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>Shaun Abram &#187; Testing</title>
	<atom:link href="http://www.shaunabram.com/tag/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shaunabram.com</link>
	<description>Java and Technology weblog</description>
	<lastBuildDate>Wed, 18 Jan 2012 00:39:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Hamcrest Matcher</title>
		<link>http://www.shaunabram.com/hamcrest-matcher/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hamcrest-matcher</link>
		<comments>http://www.shaunabram.com/hamcrest-matcher/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 05:50:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Hamcrest]]></category>
		<category><![CDATA[JUnit]]></category>
		<category><![CDATA[unittesting]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=1157</guid>
		<description><![CDATA[As a follow up to the Hamcrest post I made yesterday, I wanted to post an example of my own Hamcrest matcher implementation. This matcher tests if a string contains a specified number of substrings. An example usage could be: String sql = "select a,b,c from tableA"; assertThat(sql, hasNumberOfSubstrings(",", 2)); See the source code below. [...]]]></description>
			<content:encoded><![CDATA[<p>As a follow up to the <a href="http://www.shaunabram.com/hamcrest/">Hamcrest post</a> I made yesterday, I wanted to post an example of my own Hamcrest matcher implementation. This matcher tests if a string contains a specified number of substrings.<br />
An example usage could be:</p>
<pre><code>    String sql = "select a,b,c from tableA";
    assertThat(sql, hasNumberOfSubstrings(",", 2));</code></pre>
<p>See the source code below. I have been reading up on OSS licenses recently and decided to release this using the same license as <a href="http://code.google.com/p/hamcrest/">Hamcrest</a> &#8211; the <a href="http://www.opensource.org/licenses/bsd-license.php">new BSD license</a>.</p>
<p>I have also attached a <a href="http://www.shaunabram.com/HasNumberOfSubStrings_Hamcrest_Matcher.jar">jar</a> which includes the associated unit tests, although you will need the hamcrest-unit-test project to compile, which can be <a href="http://code.google.com/p/hamcrest/downloads/list">downloaded</a> as part of the hamcrest all-in-one jar.<br />
<span id="more-1157"></span> </p>
<pre><code>
package com.shaunabram.hamcrest;

import java.util.regex.Pattern;
import org.hamcrest.*;

/**
 * Matcher which tests if a string contains a specified number of substrings.
 *
 * @author sabram
 */
public class HasNumberOfSubstrings extends TypeSafeMatcher&lt;String&gt; {

    private final String substring;
    private final int count;

    public HasNumberOfSubstrings(String substring, int count) {
        this.substring = substring;
        this.count = count;
    }

    @Override
    protected boolean matchesSafely(String item) {
        Pattern p = Pattern.compile(substring);
        java.util.regex.Matcher m = p.matcher(item);
        int actualCount = 0;
        while (m.find()) {
            actualCount++;
        }
        if (actualCount == count) return true;
        else return false;
    }

    public void describeTo(Description description) {
        description.appendText("String containing ")
            .appendText(count + " occurences of ")
            .appendText(substring);

    }

    @Override
    public void describeMismatchSafely(String item, Description mismatchDescription) {
      mismatchDescription.appendValue(count)
                         .appendText(" occurence(s) of ")
                         .appendValue(substring)
                         .appendText(" in ")
                         .appendText(item);
    }

    @Factory
    public static Matcher&lt;String&gt; hasNumberOfSubstrings(String substring, int count) {
        return new HasNumberOfSubstrings(substring, count);
    }

}

</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/hamcrest-matcher/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hamcrest</title>
		<link>http://www.shaunabram.com/hamcrest/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hamcrest</link>
		<comments>http://www.shaunabram.com/hamcrest/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 03:33:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Hamcrest]]></category>
		<category><![CDATA[JUnit]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=1014</guid>
		<description><![CDATA[Hamcrest is a framework for writing matcher objects. Matchers have a variety of uses, but are particularly useful when writing unit tests. Instead of using JUnit&#8217;s assertEquals methods, we use Hamcrest&#8217;s assertThat construct with one (or more) of the many Matchers available. For example assertTrue(a.equalTo(b)); becomes assertThat(a, equalTo(b)); A small change in this example, but [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/hamcrest/wiki/Tutorial">Hamcrest</a> is a framework for writing matcher objects. <a href="http://www.jmock.org/matchers.html">Matchers</a> have a variety of uses, but are particularly useful when writing unit tests. Instead of using JUnit&#8217;s assertEquals methods, we use Hamcrest&#8217;s assertThat construct with one (or more) of the many Matchers available. For example</p>
<pre><code>    assertTrue(a.equalTo(b));</code></pre>
<p>becomes</p>
<pre><code>    assertThat(a, equalTo(b));</code></pre>
<p>A small change in this example, but Hamcrest&#8217;s benefits are many, enabling you to write much more flexible tests that are easier to read and have more meaningful failure messages.<br />
<span id="more-1014"></span><br />
<br/></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#benefits">Benefits of using Hamcrest</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#improvedReadability">Improved readability of tests</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#easierFailure">Better failure messages</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#combineMatcher">Combine Matchers</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#customMatcher">Custom Matchers</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#limitations">Limitations</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#whenNotToUse">Don&#8217;t use if JUnit will do</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#findingMatchers">Finding the right Matcher</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#setup">Setup</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#troubleShooting">Trouble Shooting</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#links">Links</a></p>
<p><a name="benefits"></a><br />
<br/></p>
<h3>Benefits of using Hamcrest</h3>
<p><br/><br />
<a name="improvedReadability"></a></p>
<h4>Improved readability of tests</h4>
<p>The following code, which utilizes the Hamcrest API, is easy to understand, even if you have no understanding of Hamcrest, or Java for that matter:</p>
<pre><code>    assertThat(car, is(equalTo(ferrari));
    assertThat(cars, hasItems(ferarri, porsche));</code></pre>
<p>Basically, Hamcrest provides a <a href="http://en.wikipedia.org/wiki/Fluent_interface">fluent API</a>.</p>
<p><a name="easierFailure"></a><br />
<br/></p>
<h4>Better failure messages</h4>
<p>This is one of the biggest advantages of using Hamcrest.<br />
For example, if you run the following test, which makes use of JUnit&#8217;s assertTrue method:</p>
<pre><code>
    @Test
    public void testGreatThan_JUnit() {
        int minimumPrice = 0;
        int actualPrice = -1;
        //using org.junit.Assert.assertTrue
        assertTrue(actualPrice &gt; minimumPrice);
    }</code></pre>
<p>You get the following terse and uninformative error:</p>
<blockquote><p>java.lang.AssertionError</p></blockquote>
<p>However if you rewrite the test to use Hamcrest&#8217;s assertThat method with the greaterThan matcher, as follows:</p>
<pre><code>
    @Test
    public void testGreaterThan_Hamcrest() {
        int minimumPrice = 0;
        int actualPrice = -1;
        //using org.hamcrest.MatcherAssert.assertThat
        //and  org.hamcrest.Matchers.greaterThan
        assertThat(actualPrice, greaterThan(minimumPrice));
    }</code></pre>
<p>You would get the following much more informative error message:</p>
<blockquote><p>
java.lang.AssertionError:<br />
Expected: a value greater than <0><br />
     but: <-1> was less than <0>
</p></blockquote>
<p>Basically, assertThat will tell you what was expected and what the value actually was where as assertTrue will only tell you that you got false where you expected true.<br />
(You can of course put an explicit error message in the JUnit assertion yourself of course, as in:<br />
assertTrue(&#8220;Expected a value greater than &#8221; + minimumPrice, actualPrice > minimumPrice);<br />
But Hamcrest is more descriptive and avoids the extra effort.)</p>
<p><a name="combineMatchers"></a></p>
<h4>Combinations of Matchers</h4>
<p>Hamcrest allows you to use weird and wonderful combinations of Matchers. The obvious example is using not(), but other combinations can be achieved using Matchers such as both(), either(), or(), anyOf(), and many more.</p>
<p><a name="customMatcher"></a></p>
<h4>Create your own Matchers</h4>
<p>You can also create your own custom Matchers too, by implementing the Matcher interface. I wrote a blog post with an <a href="http://www.shaunabram.com/hamcrest-matcher/">example of a custom matcher</a>, but you can also find good examples <a href="http://code.google.com/p/hamcrest/wiki/Tutorial#Writing_custom_matchers">here</a> and <a href="http://blogs.atlassian.com/developer/2009/06/how_hamcrest_can_save_your_sou.html">here</a>.<br />
<br/><br />
Finally, as a wrap up to the benefits of using Hamcrest, see the <a href="http://junit.sourceforge.net/doc/ReleaseNotes4.4.html">JUnit release notes</a> which includes a description of using the Matcher mechanism.<br />
<a name="limitations"></a><br />
<br/></p>
<h3>Limitations</h3>
<p><a name="whenNotToUse"></a><br />
<br/></p>
<h4>Don&#8217;t use if JUnit will do</h4>
<p>If there is already a suitable JUnit method to use, there may not be any benefit to using a Hamcrest Matcher. Specifically, if you are just comparing primitive or String values, JUnit&#8217;s overloaded assertEquals methods should be adequate. For example, the follow two test approaches are both fairly easy to read and give the same message on test failure:</p>
<pre>
<code>	@Test
    	public void testEquals_JUnit() {
	    int expectedPrice = 0;
	    int actualPrice = -1;
	    //using org.junit.Assert.assertEquals
	    assertEquals(expectedPrice, actualPrice);
	    //java.lang.AssertionError: expected:&lt;0&gt; but was:&lt;-1&gt;
	}

	@Test
	public void testEquals_Hamcrest() {
	    int expectedPrice = 0;
	    int actualPrice = -1;
	    //using org.hamcrest.MatcherAssert.assertThat
            //and org.hamcrest.Matchers.equalTo
	    assertThat(actualPrice, equalTo(expectedPrice));
	    //java.lang.AssertionError: Expected: &lt;0&gt; but: was &lt;-1&gt;
	}</code>
</pre>
<p>However, for anything more complicated than primitive or String comparison, Hamcrest&#8217;s Matchers are likely to be much more useful.</p>
<p><a name="findingMatchers"></a><br />
<br/></p>
<h4>Finding the right Matcher</h4>
<p>One of the issues I have with Hamcrest is that the matchers are not all available in one place. It makes finding the correct matcher difficult and also means your IDE&#8217;s code assist, or import organizer, is not likely to be much help either. Most matchers are accessible via the <a href="http://www.shaunabram.com/hamcrest1.2-javadoc/org/hamcrest/Matchers.html">Matchers</a> class (although confusingly there is also the <a href="http://www.shaunabram.com/hamcrest1.2-javadoc/org/hamcrest/CoreMatchers.html">CoreMatchers</a> class, which seems to be a subset &#8211; I never quite figured that one out&#8230;). But other matchers are located in other classes and packages.</p>
<p>Example 1<br />
The very useful <a href="http://www.shaunabram.com/hamcrest1.2-javadoc/org/hamcrest/Matchers.html#hasItem(T)">hasItem</a> matcher is available in the aforementioned Matchers class:</p>
<pre><code>    import static org.hamcrest.MatcherAssert.assertThat;
    import static org.hamcrest.Matchers.hasItem;

    public class HamcrestExamples {

        List&lt;String&gt; list = new ArrayList&lt;String&gt;();

	@Before
	public void setup() {
		list.add("itemA");
		list.add("itemB");
	}

	@Test
	public void test() {
		assertThat(list, hasItem("itemA"));
	}
}</code></pre>
<p>But if you want to use the very similar <a href="http://www.shaunabram.com/hamcrest1.2-javadoc/org/hamcrest/core/IsCollectionContaining.html#hasItems%28T...%29">hasItems</a> matcher, you need to know (or trawl the javadocs to find out) it is in the <a href="http://www.shaunabram.com/hamcrest1.2-javadoc/org/hamcrest/core/IsCollectionContaining.html">IsCollectionContaining</a> class.</p>
<pre><code>    import static org.hamcrest.core.IsCollectionContaining.hasItems;
    ...
        @Test
	public void testHasItems() {
		assertThat(list, hasItems("itemA", "itemB"));
	}</code></pre>
<p>Example 2<br />
There is a useful containsString() method in the Matchers class that returns a Matcher to check is a String contains a sub-String, but if you want to check if a String contains several sub-Strings, in order, you need to know to look at the <a href="http://www.shaunabram.com/hamcrest1.3RC2-javadoc/org/hamcrest/text/StringContainsInOrder.html">StringContainsInOrder</a> class.</p>
<p>Notes: </p>
<ul>
<li>It looks like the above hasItems example will be remedied in 1.3 where hasItems will be made available via the Matchers class.</li>
<li>There is a very similar testing library that seems to overcome this problem called <a href="http://docs.codehaus.org/display/FEST/Fluent+Assertions+Module">Fluent Assertions module</a> from <a href="http://fest.easytesting.org/">FEST</a>. FEST has all the matchers available via a single static import. (Also, see this interesting <a href="http://docs.codehaus.org/display/FEST/Comparing+to+Hamcrest">comparison</a> with Hamcrest  &#8211; I see no reason not to use both)</li>
</ul>
<p><a name="setup"></a><br />
<br/></p>
<h3>Setup</h3>
<ol>
<li>Download the Hamcrest jar(s) from <a href="http://code.google.com/p/hamcrest/downloads">http://code.google.com/p/hamcrest/downloads</a> (using the all-in-one Jar is easiest)<br />
<blockquote><p>Note that JUnit does ship with some Hamcrest classes included. However, I prefer to use the Hamcrest jars directly because</p>
<ul>
<li>JUnit only includes the core Hamcrest (hamcrest-core) API classes. A much larger library of Matcher implementations is available by also using the hamcrest-library jars. Personally, I simply use the hamcrest-all.jar, which includes all the available Hamcrest classes.
</li>
<li>The package names in JUnit are different than those in Hamcrest e.g.  <em>org.hamcrest.MatcherAssert.assertThat</em> versus <em>org.junit.Assert.assertThat</em><br />
I prefer to keep things simply by always referring to the native org.hamcrest packages directly.
</li>
</ul>
<p>If you do choose to use the Hamcrest jars directly, it is also advisable to use the junit-dep jars. These come without the Hamcrest classes included, avoiding any uncertainty about which Hamcrest classes you are actually using.
</p></blockquote>
<li>Add the Hamcrest jar(s) to your classpath or maven dependencies.</li>
<li>Statically import Hamcrest&#8217;s assertThat construct and the Hamcrest matchers:<br />
<blockquote><p>import static org.hamcrest.MatcherAssert.assertThat;<br />
import static org.hamcrest.Matchers.*;</p></blockquote>
</li>
<li>Start using Hamrests&#8217;s assertThat in your unit tests, instead of JUnit&#8217;s assertTrue and assertEquals etc<br />
e.g. instead of</p>
<pre><code>    assertEquals(expectedValue, actualValue);</code></pre>
<p>use</p>
<pre><code>    assertThat(actualValue, equalTo(expectedValue));</code></pre>
</li>
</ol>
<p>Perhaps in future postings I will talk about how to use Hamcrest&#8217;s Matchers with Mock object frameworks such as <a href="http://easymock.org/">EasyMock</a> and <a href="http://www.jmock.org/">JMock</a>.</p>
<p><a name="troubleShooting"></a><br />
<br/></p>
<h3>Trouble Shooting</h3>
<p>Error:</p>
<blockquote><p>java.lang.SecurityException: class &#8220;org.hamcrest.Matchers&#8221;&#8216;s signer information does not match signer information of other classes in the same package</p></blockquote>
<p>You simply need to make sure the Hamcrest jar comes before JUnit in your classpath. Alternatively, use junit-dep.</p>
<p>Error:</p>
<blockquote><pre><code>cannot find symbol method
assertThat(java.util.List&lt;ExampleClass&gt;,org.hamcrest.Matcher&lt;java.lang.Iterable&lt;java.lang.Object&gt;&gt;)</code></pre>
</blockquote>
<p>or</p>
<blockquote><pre><code>cannot find symbol method
assertThat(java.util.List&lt;ExampleClass&gt;,org.hamcrest.Matcher&lt;java.lang.Iterable&lt;? super
java.lang.Object&gt;&gt;)</code></pre>
</blockquote>
<p>This error can happen with any iterable (not just Lists, as in the above example) using hasItem or hasItems (and possibly other matchers too). It is a known issue with Hamcrest at the moment and is documented <a href="http://code.google.com/p/hamcrest/issues/detail?id=84">here</a>, along with some fixes. I took the not-pretty-but-works option of declaring the Matcher in a local variable first<br />
e.g.</p>
<pre><code>    assertThat(list, hasItems(item1, item2));</code></pre>
<p>becomes</p>
<pre><code>    Matcher&lt;java.lang.Iterable&lt;ExampleClass&gt;&gt; matcher = hasItems(item1, item2);
    assertThat(list, matcher);</code></pre>
<p>Like I said, not-pretty-but-works.</p>
<p><a name="links"></a><br />
<br/></p>
<h3>Links</h3>
<ul>
<li><a href="http://code.google.com/p/hamcrest/">Hamcrest home page</a></li>
<li><a href="http://code.google.com/p/hamcrest/wiki/Tutorial">Hamcrest Tutorial</a></li>
<li><a href="http://www.shaunabram.com/hamcrest1.2-javadoc/index.html">Hamcrest API docs</a> &#8211; At the time of writing, the Hamcrest API docs seem surprisingly hard to come by online and there is an <a href="http://code.google.com/p/hamcrest/issues/detail?id=81">ticket</a> for this on the Hamcrest site. There also seems to be <a href="http://code.google.com/p/hamcrest/issues/detail?id=98">some issues</a> when building the javadocs for yourself:<br />
In the mean time, I have taken the liberty of posting them on my site here:</p>
<ul>
<li><a href="http://www.shaunabram.com/hamcrest1.2-javadoc/index.html">Hamcrest 1.2 javadocs</a></li>
<li><a href="http://www.shaunabram.com/hamcrest1.3RC2-javadoc/index.html">Hamcrest 1.3 RC2 javadocs</a></li>
</ul>
<p></a></p>
<li><a href="http://kentbeck.github.com/junit/javadoc/latest/">JUnit API docs</a></li>
<li><a href="http://docs.codehaus.org/display/FEST/Fluent+Assertions+Module">Fluent Assertions module</a> from <a href="http://fest.easytesting.org/">FEST</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/hamcrest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Selenium talk at SF JUG</title>
		<link>http://www.shaunabram.com/sfjug-selenium/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sfjug-selenium</link>
		<comments>http://www.shaunabram.com/sfjug-selenium/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 07:26:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[JUG]]></category>
		<category><![CDATA[q]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[sfjug]]></category>
		<category><![CDATA[unittesting]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=749</guid>
		<description><![CDATA[I attended another great San Francisco JUG meeting tonight, this time on How to use Selenium with Maven/Ant to automate testing of web apps. The talk was given by Chris Bedford, from Build Lackey Labs &#8211; &#8220;Automating the Monkey Work Out and the Quality In!&#8221;. Overall, I thought this was a great talk by Chris. [...]]]></description>
			<content:encoded><![CDATA[<p>I attended another great <a href="http://www.sfjava.org/calendar/10674274/">San Francisco JUG</a> meeting tonight, this time on <a href="http://www.sfjava.org/calendar/11982857/">How to use Selenium with Maven/Ant to automate testing of web apps</a>.</p>
<p>The talk was given by Chris Bedford, from <a href="http://buildlackey.com/">Build Lackey Labs</a> &#8211; &#8220;Automating the Monkey Work Out and the Quality In!&#8221;. Overall, I thought this was a great talk by Chris. He clearly has a huge amount of experience creating automated tests and integrating them with build tools and he gave a well structured, interesting, well delivered presentation. I have posted a copy of <a href="http://www.shaunabram.com/attachments/testing-java-web-apps-with-selenium5.ppt">Chris&#8217;s slides</a> and I think the video will be posted on the SF JUG site at some point, but I have also posted my notes from the presentation below&#8230;<br />
<span id="more-749"></span></p>
<h3>Selenium Overview</h3>
<p>Chris started off with an overview of <a href="http://seleniumhq.org/">Selenium</a> &#8211; a tool for automating tests for web based applications. He then introduced us to the Selenium IDE &#8211; a Firefox add-on that allows you to set up tests by recording clicks on a web page, or by manually entering commands. The tests can then be played back as part of your automated test suite.</p>
<h3>Creating Selenium Tests</h3>
<p>Chris showed us the process by both executing an existing test he had already setup, and by walking us through the creation of a new test, which loaded a page, waited for text to be present, clicked on a link, and confirmed that text was present. The test was a html file, but he showed how to export it as <a href="http://testng.org/doc/index.html">TestNG</a> and <a href="http://www.junit.org/">JUnit</a> tests  (although both exports resulted in kind of ugly java code!)</p>
<h3>Possible hiccups with Selenium</h3>
<p>One of the things I thought Chris did well was, in addition to pointing out all the many great things about Selenium, he also pointed out some of the slight issues with Selenium that he has encountered during his time using it, such as</p>
<ul>
<li>Difficulties getting the initial Open page to work</li>
<li>Issues with where the test files get saved</li>
<li>Making sure you have the tests run slow to start with (to avoid timing/loading issues)</li>
<li>The Selenium IDE may be difficult to get working with IE (Firefox is fine)</li>
</ul>
<h3>Selenium Components</h3>
<p>The main Selenium section then finished up with a quick over of the various Selenium Components:</p>
<ul>
<li>Selenium IDE</li>
<li>Selenese Commands</li>
<li>Selenium RC (Remote Control)</li>
</ul>
<p>Chris also had a section on the &#8216;<a href="http://en.wikipedia.org/wiki/Same_origin_policy">same origin</a>&#8216; JavaScript  policy that Selenium manages to circumvent by using the Selenium RC Server. He managed to explain the issue in simple terms.</p>
<h3>Other functional test alternatives</h3>
<p>Chris discussed other functional test alternatives by comparing <a href="http://webtest.canoo.com/webtest/manual/WebTestHome.html">Canoo</a> to Selenium (Canoo is also an automated web app testing framework).</p>
<p>Chris also mentionted <a href="http://code.google.com/p/umangite/">Umangite</a>, Chris Richardson&#8217;s open source testing framework that makes Selenium tests easier to write. I have used this before, and agree it is worth checking out&#8230;</p>
<h3>Using Selenium with Build Tools</h3>
<p>He then discussed using Maven with Selenium, including using <a href="http://cargo.codehaus.org/">Cargo</a> (e.g. using the <a href="http://cargo.codehaus.org/Maven2+plugin">cargo maven2 plugin</a>). Cargo is a set of APIs that assists in</p>
<ul>
<li>installing web containers, such as Tomcat, JBoss</li>
<li>booting and shutting them down</li>
<li>deploying web apps (.wars, .ears)</li>
</ul>
<p>Chris finished the Selenium &#038; build tools section with a quick run through of using Selenium with <a href="http://ant.apache.org/">Ant</a>.</p>
<h4>Continuous Integration</h4>
<p>The final section of the presentation was a talk on Continuous Integration (CI). Chris described CI as: </p>
<ul>
<li>A dedicated box (see my follow up question below!) that runs regular full builds (including tests) of your software</li>
<li>Build triggers when any developer checks into SCM</li>
<li>Team is notified of any issues</li>
</ul>
<p>And talked about how Selenium can be used with <a href="http://hudson-ci.org/">Hudson</a> &#8211; a very cool CI tool from Sun. This leads well into <a href="http://www.sfjava.org/calendar/12296161/">next month&#8217;s SF JUG talk</a>!</p>
<h3>Q&#038;A</h3>
<p>Q: Do you have any info on WebDriver merging with Selenium?<br />
A: No, but sounds interesting!</p>
<p>Q: How closely do test writers work with marketing people?<br />
A: Chris suggested checking out the <a href="http://www.easyb.org/">easyb</a> framework, a behavior driven development framework that allows you to write conditions in a very abstract level, using a DSL that marketers can use and understand. He also suggested looking at the <a href="http://www.fitnesse.org/">fitnesse</a> framework.</p>
<p>Q: I asked Chris via email after the talk what he meant by needing &#8216;dedicated&#8217; box/server for Continuous Integration.<br />
A: He clarified that by &#8216;dedicated&#8217;, he just meant that the build box  should not be a box that you are doing development on, and that there isn&#8217;t anything wrong with having a mix of services on one machine. e.g. having a qa box that has the CI server and maybe hosts the bug tracking system as well&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/sfjug-selenium/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Running Hibernate unit tests with Maven</title>
		<link>http://www.shaunabram.com/hibernate-maven-unit-tests/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hibernate-maven-unit-tests</link>
		<comments>http://www.shaunabram.com/hibernate-maven-unit-tests/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 08:37:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=42</guid>
		<description><![CDATA[I recently converted a project I have been working on to use Maven. After setting up all the dependencies in the pom, I got everything compiling fine but ran into problems getting the unit tests to pick up the hibernate config (hibernate.cfg.xml) and hibernate mapping (*.hbm.xml) files. With hindsight, it is straightforward, but it took [...]]]></description>
			<content:encoded><![CDATA[<p>I recently converted a project I have been working on to use <a href="http://maven.apache.org/">Maven</a>. After setting up all the dependencies in the pom, I got everything compiling fine but ran into problems getting the unit tests to pick up the hibernate config (hibernate.cfg.xml) and hibernate mapping (*.hbm.xml) files. With hindsight, it is straightforward, but it took me a while to figure it out so I thought I&#8217;d post the solution here.</p>
<p>Initially, I had my hibernate.cfg.xml file in the following directory</p>
<p style="padding-left: 30px;">my-app/src/main/java</p>
<p>And when I first tried to run my hibernate unit tests (mvn test), I got this error:</p>
<p style="padding-left: 30px;">SessionFactory creation failed.org.hibernate.HibernateException: /hibernate.cfg.xml not found</p>
<p>Some checking of the maven docs and some forums revealed the following possible solutions:<br />
1) Copy the hibernate.cfg.xml file to</p>
<p style="padding-left: 30px;">my-app/target/classes</p>
<p>This works, however I think it is a hack as the target folder is generated rather than being somewhere you should actually manually create files.<br />
2) The next solution I found suggested moving the hibernate.cfg.xml to</p>
<p style="padding-left: 30px;">my-app/src/main/resources</p>
<p>This works well as the contents of this folder are copied to the base level of the my-app/target/classes folder so it is basically a &#8216;more correct&#8217; solution than the first.<br />
3) The next and I think best solution was to create a new, duplicate hibernate.cfg.xml inside</p>
<p style="padding-left: 30px;">my-app/src/test/resources</p>
<p>This allows a different hibernate.cfg.xml file to be used for testing and, for example, facilitates connecting to a different database (such as <a href="http://hsqldb.org/">hsqldb</a>) for testing while continuing to use your regular database (such as <a href="http://www.mysql.com/">MySQL</a>) for the app itself.</p>
<p>A couple of points to note:</p>
<p>1) The hibernate mapping files (i.e. the *.hbm.xml files) should also be in the resources folder (in whatever directory structure you choose) to ensure that these too are accessible by the unit tests.</p>
<p>2) I am not (yet) using Spring with the hibernate components, which would likely have changed the above setup.</p>
<p>Refs/links</p>
<p style="padding-left: 30px;"><a href="http://maven.apache.org/guides/getting-started/index.html#How_do_I_add_resources_to_my_JAR">http://maven.apache.org/guides/getting-started/index.html#How_do_I_add_resources_to_my_JAR</a></p>
<p style="padding-left: 30px;"><a href="http://www.mail-archive.com/users@maven.apache.org/msg54720.html">http://www.mail-archive.com/users@maven.apache.org/msg54720.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/hibernate-maven-unit-tests/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Silicon Valley Code Camp Notes</title>
		<link>http://www.shaunabram.com/attending-silicon-valley-code-camp/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=attending-silicon-valley-code-camp</link>
		<comments>http://www.shaunabram.com/attending-silicon-valley-code-camp/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 19:58:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[threading]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=22</guid>
		<description><![CDATA[I am at the Silicon Valley Code Camp at the moment. I will try to post some notes on the various talks I attend below&#8230; Day 1: Session 1: JavaScript Session 2: Easing into Agile Session 3: Building Better Tests in Java Session 4: What is Python? Day 2: Session 1: Basics of Threading Session [...]]]></description>
			<content:encoded><![CDATA[<p>I am at the <a href="http://www.siliconvalley-codecamp.com/">Silicon Valley Code Camp</a> at the moment.</p>
<p>I will try to post some notes on the various talks I attend below&#8230;</p>
<p>Day 1:</p>
<ul>
<li>Session 1: <a href="http://shaunabram.com/code-camp-javascript">JavaScript</a></li>
<li>Session 2: <a href="http://www.shaunabram.com/code-camp-easing-into-agile">Easing into Agile</a></li>
<li>Session 3: <a href="http://www.shaunabram.com/code-camp-building-better-tests-in-java">Building Better Tests in Java</a></li>
<li>Session 4: <a href="http://www.shaunabram.com/code-camp-what-is-python">What is Python?</a></li>
</ul>
<p>Day 2:</p>
<ul>
<li>Session 1: <a href="http://www.shaunabram.com/?page_id=24">Basics of Threading </a></li>
<li>Session 2: Introduction to Grails</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/attending-silicon-valley-code-camp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FindBugs</title>
		<link>http://www.shaunabram.com/findbugs/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=findbugs</link>
		<comments>http://www.shaunabram.com/findbugs/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 19:46:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.shaunabram.com/?p=7</guid>
		<description><![CDATA[Came across this really neat tool that can actually find bugs in your code. It uses &#8216;static analysis&#8217; to find instances of bug patterns &#8211; code instances that are likely to be errors. I was pretty skeptical until I ran it on some code and was impressed by the results. It found loads of possible [...]]]></description>
			<content:encoded><![CDATA[<p>Came across this really neat tool that can actually find bugs in your code. It uses &#8216;static analysis&#8217; to find instances of bug patterns &#8211; code instances that are likely to be errors. I was pretty skeptical until I ran it on some code and was impressed by the results. It found loads of possible problems. I&#8217;ll definitely be using it again.</p>
<p>Check it out at <a href="http://findbugs.sourceforge.net/">http://findbugs.sourceforge.net/</a></p>
<p>Update: Found recommendations for another tool called JLint, which is supposed to be particularly good for spotting potential deadlocks so perhaps worth using when testing threaded code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunabram.com/findbugs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

