<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Weiqi Gao&#039;s Observations - testing tag</title>
  <link>http://www.weiqigao.com/blog/tags/testing/</link>
  <description>Sharing My Experience...</description>
  <language>en</language>
  <copyright>Weiqi Gao</copyright>
  <lastBuildDate>Fri, 11 May 2012 12:48:36 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  <image>
    <url>http://pebble.sourceforge.net/common/images/powered-by-pebble.gif</url>
    <title>Weiqi Gao&#039;s Observations</title>
    <link>http://www.weiqigao.com/blog/</link>
  </image>
  
  
  <item>
    <title>Java News Brief (JNB): Migrating To JUnit 4</title>
    <link>http://www.weiqigao.com/blog/2007/09/18/java_news_brief_jnb_migrating_to_junit_4.html</link>
    
      
        <description>
          &lt;p&gt;In the August issue of the &lt;a href= &#034;http://www.ociweb.com/&#034; &gt;OCI&lt;/a&gt; &lt;a href=&#034;http://www.ociweb.com/jnb/jnbAug2007.html&#034; &gt;Java News Brief (JNB)&lt;/a&gt;, Charles Sharp gave a pretty detailed prescription for migrating from JUnit 3 to JUnit 4.  Besides the normal &#034;this is what changed&#034; material, Charles also points out some of the new features in JUnit 4.4.  One of them is described thusly:&lt;/p&gt;

&lt;blockquote&gt;
&lt;a href= &#034;http://www.ociweb.com/jnb/jnbAug2007.html&#034; &gt;Charles Sharp&lt;/a&gt;: JUnit 4.4 introduces a new assert, &lt;code&gt;assertThat&lt;/code&gt;, and some assumptions: &lt;code&gt;assumeThat&lt;/code&gt;, &lt;code&gt;assumeNotNull&lt;/code&gt;, &lt;code&gt;assumeNoException&lt;/code&gt;, and &lt;code&gt;assumeTrue&lt;/code&gt;.  The 4.4 release notes give credit to Joe Walnes for the &lt;code&gt;assertThat&lt;/code&gt; assertion mechanism. Those familiar with the jMock project will probably recognize it.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;assertThat&lt;/code&gt; assertions require a parameter of &lt;code&gt;org.hamcrest.Matcher&lt;/code&gt; type. JUnit 4.4 provides several of these Matcher classes by including a third-party package, org.hamcrest.core as well as including some in the package, org.junit.matchers.  According to the release notes, this is the first time a third-party package has been shipped with JUnit. A good start on using this assertion is found in a &lt;a href= &#034;http://joe.truemesh.com/blog/000511.html&#034; &gt;blog post by Joe Walnes&lt;/a&gt;, in which he explains the rationale and intended usage of &lt;code&gt;assertThat&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That&#039;s something I would not have paid attention to.  If you haven&#039;t figured out, I have a tendency to do the old thing.  I would have been perfectly happy using JUnit 4 with just the &lt;tt&gt;@Before&lt;/tt&gt;, &lt;tt&gt;@After&lt;/tt&gt; and &lt;tt&gt;@Test&lt;/tt&gt; annotations.  Now I&#039;m curious about this &lt;tt&gt;assertThat&lt;/tt&gt; thing.  And I wrote the following test:&lt;/p&gt;

&lt;pre style=&#034;margin-left:3em&#034;&gt;import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
import org.junit.Test;

public class Foo {
    @Test()
    public void foo() {
        Object o = new Object();
        Object o1 = new Object();
        assertThat(o, anyOf(sameInstance(o), sameInstance(o1)));
    }
}&lt;/pre&gt;

&lt;p&gt;Hmmm, my unit tests can become a lot more interesting.&lt;/p&gt;

&lt;p&gt;Got your attention?  Go read the &lt;a href= &#034;http://www.ociweb.com/jnb/jnbAug2007.html&#034; &gt;whole thing.&lt;/a&gt;&lt;/p&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2007/09/18/java_news_brief_jnb_migrating_to_junit_4.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2007/09/18/java_news_brief_jnb_migrating_to_junit_4.html</guid>
    <pubDate>Tue, 18 Sep 2007 22:27:56 GMT</pubDate>
  </item>
  
  <item>
    <title>Selenium: Automatable In-browser Functional Testing For Web Apps</title>
    <link>http://www.weiqigao.com/blog/2006/04/20/selenium_automatable_in_browser_functional_testing_for_web_apps.html</link>
    
      
        <description>
          &lt;p&gt;&lt;a href=&#034;http://www.weiqigao.com/blog/images/selenium-ide.png&#034;&gt;
&lt;img src=&#034;http://www.weiqigao.com/blog/images/selenium-ide.png&#034; title=&#034;Selenium IDE&#034; border=&#034;0&#034; hspace=&#034;12&#034; valign=&#034;top&#034; align=&#034;right&#034;/&gt;
&lt;/a&gt;At today&#039;s OCI Java lunch, our resident automated building and testing zealot &lt;a href= &#034;http://www.ociweb.com/education/instructors/mario_aquino.html&#034; &gt;Mario Aquino&lt;/a&gt; talked about an interesting tool called &lt;a href= &#034;http://www.openqa.org/selenium/&#034; &gt;Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I forgot to blog it while he&#039;s talking.  So I&#039;m doing a little bit of catching up tonight.  And all of this is from my impression from one hour of presentation/demonstration.&lt;/p&gt;

&lt;p&gt;Selenium&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;tests web applications&lt;/li&gt;
&lt;li&gt;while running them inside the browser&lt;/li&gt;
&lt;li&gt;with FIT style table driven test scripts&lt;/li&gt;
&lt;li&gt;that exercises the HTML page&#039;s links, buttons, text fields, etc.&lt;/li&gt;
&lt;li&gt;and asserts and verifies various on-screen values&lt;/li&gt;
&lt;li&gt;for fields selected by IDs, names, or XPath expressions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Selenium scripts&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;have alternative representations as&lt;/li&gt;
&lt;li&gt;Java code that can be put into JUnit tests and become part of the hourly build&lt;/li&gt;
&lt;li&gt;Ruby code that can be invoked through rake&lt;/li&gt;
&lt;li&gt;or Selenium &#034;wiki&#034; code that&#039;s just a tad easier to write than HTML tables&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is a &lt;a href= &#034;http://www.openqa.org/selenium-ide/&#034; &gt;Selenium IDE&lt;/a&gt; that can be installed as a Firefox extension.  It allows one to write Selenium scripts by recording a browsing session. (In the screenshot you can see me clicking on the Save button to save a draft of this post, and then clicking on the link to the artile on the Drafts screen to resume editing.)&lt;/p&gt;

&lt;p&gt;Mario did mention a few quirks.  One is that if ran as JUnit tests, Selenium tends to not close the browser when it&#039;s done, leaving thousands of open browsers behind on the testing machine.  Another is that &#034;clickAndWait&#034; doesn&#039;t work with AJAXy buttons or links.&lt;/p&gt;

&lt;p&gt;Selenium was developed by &lt;a href= &#034;http://www.thoughtworks.com&#034; &gt;&lt;b&gt;Thought&lt;/b&gt;Works&lt;/a&gt; for one of their projects and is now Open Source (Apache 2.0 License).&lt;/p&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2006/04/20/selenium_automatable_in_browser_functional_testing_for_web_apps.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2006/04/20/selenium_automatable_in_browser_functional_testing_for_web_apps.html</guid>
    <pubDate>Fri, 21 Apr 2006 02:54:31 GMT</pubDate>
  </item>
  
  <item>
    <title>Java News Brief (JNB): The Framework for Integrated Tests (Fit)</title>
    <link>http://www.weiqigao.com/blog/2005/12/14/java_news_brief_jnb_the_framework_for_integrated_tests_fit.html</link>
    
      
        <description>
          &lt;p&gt;If you have heard about &lt;a href= &#034;http://fit.c2.com/&#034; &gt;Fit&lt;/a&gt; for some time, but never had the time to investigate it, then &lt;a href= &#034;http://ociweb.com/jnb/jnbDec2005.html&#034; &gt;this month&#039;s JNB article&lt;/a&gt; is for you.&lt;/p&gt;

&lt;p&gt;The idea is very simple.&lt;/p&gt;

&lt;p&gt;Your write your test scripts in HTML:&lt;/p&gt;

&lt;pre style=&#034;margin-left:3em&#034;&gt;&amp;lt;table border=&#034;1&#034; cellpadding=&#034;2&#034; cellspacing=&#034;2&#034;&gt;
  &amp;lt;tbody&gt;
    &amp;lt;tr&gt;
      &amp;lt;td style=&#034;vertical-align: top;&#034; colspan=&#034;2&#034; rowspan=&#034;1&#034;&gt;ValidateCustomerName&amp;lt;/td&gt;
    &amp;lt;/tr&gt;
    &amp;lt;tr&gt;
      &amp;lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;
        &amp;lt;span style=&#034;font-style: italic;&#034;&gt;customer name&amp;lt;/span&gt;
      &amp;lt;/td&gt;
      &amp;lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;
        &amp;lt;span style=&#034;font-style: italic;&#034;&gt;valid()&amp;lt;/span&gt;
      &amp;lt;/td&gt;
    &amp;lt;/tr&gt;
    &amp;lt;tr&gt;
      &amp;lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;
      &amp;lt;/td&gt;
      &amp;lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;error&amp;lt;/td&gt;
    &amp;lt;/tr&gt;
    &amp;lt;tr&gt;
      &amp;lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;Mario&amp;lt;/td&gt;
      &amp;lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;true&amp;lt/td&gt;
    &amp;lt;/tr&gt;
  &amp;lt;/tbody&gt;
&amp;lt;/table&gt;&lt;/pre&gt;

&lt;p&gt;which looks like this in a browser:&lt;/p&gt;

&lt;div style=&#034;margin-left:3em&#034;&gt;
&lt;table border=&#034;1&#034; cellpadding=&#034;2&#034; cellspacing=&#034;2&#034;&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&#034;vertical-align: top;&#034; colspan=&#034;2&#034; rowspan=&#034;1&#034;&gt;ValidateCustomerName&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;
        &lt;span style=&#034;font-style: italic;&#034;&gt;customer name&lt;/span&gt;
      &lt;/td&gt;
      &lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;
        &lt;span style=&#034;font-style: italic;&#034;&gt;valid()&lt;/span&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;
      &lt;/td&gt;
      &lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;error&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;Mario&lt;/td&gt;
      &lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;true&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;You run the thing:&lt;/p&gt;

&lt;pre style=&#034;margin-left:3em&#034;&gt;[prompt] $ &lt;b&gt;java fit.FileRunner tests.html report.html&lt;/b&gt;&lt;/pre&gt;

&lt;p&gt;And depending on if your code is right or wrong, you get either an all green report card:&lt;/p&gt;

&lt;div style=&#034;margin-left:3em&#034;&gt;
&lt;table border=&#034;1&#034; cellpadding=&#034;2&#034; cellspacing=&#034;2&#034;&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&#034;vertical-align: top;&#034; colspan=&#034;2&#034;
      rowspan=&#034;1&#034;&gt;ValidateCustomerName&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;
	&lt;span style=&#034;font-style: italic;&#034;&gt;customer name&lt;/span&gt;
      &lt;/td&gt;
      &lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;
	&lt;span style=&#034;font-style: italic;&#034;&gt;valid()&lt;/span&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt; &lt;span style=&#034;color: rgb(128, 128,
      128);&#034;&gt;null&lt;/span&gt;
      &lt;/td&gt;
      &lt;td style=&#034;background-color: rgb(207, 255, 207);&#034; rowspan=&#034;1&#034;
      colspan=&#034;1&#034;&gt;error&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;Mario&lt;/td&gt;
      &lt;td style=&#034;background-color: rgb(207, 255, 207);&#034; rowspan=&#034;1&#034;
      colspan=&#034;1&#034;&gt;true&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;or worse (from a different test):&lt;/p&gt;

&lt;div style=&#034;margin-left:3em&#034;&gt;
&lt;table style=&#034;text-align: left;&#034; border=&#034;1&#034; cellpadding=&#034;2&#034; cellspacing=&#034;2&#034;&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;check&lt;/td&gt;
      &lt;td rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;customer total balance&lt;/td&gt;
      &lt;td style=&#034;background-color: rgb(255, 207, 207);&#034;
	  rowspan=&#034;1&#034; colspan=&#034;1&#034;&gt;
	$135.00 &lt;span class=&#034;expected&#034;&gt;expected&lt;/span&gt; &lt;hr/&gt;
	$35.00 &lt;span class=&#034;expected&#034;&gt;actual&lt;/span&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;You have to write a few Java classes along the way.  But those are trivial, right? &lt;tt&gt;:)&lt;/tt&gt;&lt;/p&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2005/12/14/java_news_brief_jnb_the_framework_for_integrated_tests_fit.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2005/12/14/java_news_brief_jnb_the_framework_for_integrated_tests_fit.html</guid>
    <pubDate>Wed, 14 Dec 2005 18:26:45 GMT</pubDate>
  </item>
  
  </channel>
</rss>

