<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>acceptance-tests &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://wordpress.com/tag/acceptance-tests/</link>
	<description>Feed of posts on WordPress.com tagged "acceptance-tests"</description>
	<pubDate>Sun, 06 Jul 2008 17:40:13 +0000</pubDate>

	<generator>http://wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Database testing using Generic Fixture]]></title>
<link>http://anubhava.wordpress.com/?p=19</link>
<pubDate>Wed, 07 May 2008 15:46:25 +0000</pubDate>
<dc:creator>anubhava</dc:creator>
<guid>http://anubhava.wordpress.com/?p=19</guid>
<description><![CDATA[
As I have mentioned in my  Introduction to Generic  Fixture post that we can use Generic Fixture to]]></description>
<content:encoded><![CDATA[<div style="text-align:justify;">
<p>As I have mentioned in my <a href="http://anubhava.wordpress.com/2008/02/09/introducing-generic-fixture-for-fitnesse/"> Introduction to Generic  Fixture</a> post that we can use Generic Fixture to write acceptance tests to  validate almost any type of Java application. In my previous posts I  demonstrated how to make use of Generic Fixture to write automated web tests and  testing EJBs. Let's now see how to use Generic Fixture for writing queries  against an Oracle database.</p>
<p>We shall keep the database connection  parameters in a separate SetUp page as well as the connection closing code in a  separate TearDown page. After that we shall write our query in main test page.  That way we can utilize SetUp and TearDown pages in all of our test pages  without repeating that code again and again in for each test.</p>
<p>I am  assuming that your FitNesse server process is running on localhost on post 8000.  If that is not the case then please change the URLs accordingly.</p>
<p>To test  a database we shall need the database vendor supplied JDBC driver to be able to  make JDBC calls. In this example since we are using Oracle we are going to need  Oracle's JDBC driver jar file. You can place your JDBC driver jar file anywhere  on your system where FitNesse server is running and give the path in !path  directive of FitNesse.</p>
<p>Open a browser and enter this URL: http://localhost:8000/FitNesse.OracleSuite<br />
Since this page  doesn't already exist, it will give you a link <strong>"create this  page"</strong>, go ahead the click on this link to create a new page. Enter  following text in the new page's source.</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:90%;padding:5px;">
<pre>!*&#62; Class Path
!path ojdbc14.jar
*!
----
&#62;SetUp
&#62;TearDown
 * &#62;SelectQuery</pre>
</div>
<p>Please note that here I kept <b>JDBC driver jar file (ojdbc14.jar)</b> in FitNesse install directory therefore I could give this directive !path ojdbc14.jar. If you want to keep ojdbc14.jar at some other path then just provide your path here using <b>!path /your/path/to/ojdbc14.jar</b></p>
<p>Save your changes. Now FitNesse will show question marks ? links next to &#62;SetUp, &#62;TearDown and &#62;SelectQuery text, since these pages do not already exist. Go ahead and click on the ? link next to &#62;SetUp text and enter following text in the new page's source.</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:90%;padding:5px;">
<pre>'''Connect to Database'''
!&#124; Generic Fixture &#124; oracle.jdbc.pool.OracleDataSource &#124;
&#124; setDriverType &#124; thin &#124;
&#124; setServerName &#124; localhost &#124;
&#124; setPortNumber &#124; 1521 &#124;
&#124; setDatabaseName &#124; testdb &#124;
&#124; setUser &#124; scott &#124;
&#124; setPassword &#124; tiger &#124;
&#124; conn=getConnection &#124;</pre>
</div>
<p>Customize database connection parameters above to suite your environment. Save your changes. Now click on the ? link next to &#62;TearDown text and enter following text in the new page's source.</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:90%;padding:5px;">
<pre>'''Close the Statement'''
!&#124; Generic Fixture &#124; stmt= &#124;
&#124; close &#124;

'''Close the Connection'''
!&#124; Generic Fixture &#124; conn= &#124;
&#124; close &#124;
&#124; is closed &#124; &#124; true &#124;</pre>
</div>
<p>Save your changes. Now click on the ? link next to &#62;SelectQuery text and enter following text in the new page's source.</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:90%;padding:5px;">
<pre>'''Prepare your query'''
!&#124; Generic Fixture &#124; conn= &#124;
&#124; stmt=prepareStatement &#124; select  age, title from emp where id = ? &#124;

'''Execute your query'''
!&#124; Generic Fixture &#124; stmt= &#124;
&#124; setInt &#124; 1 &#124; 1234 &#124;
&#124; resultSet=executeQuery &#124;

'''Examine the Result Set'''
!&#124; Generic Fixture &#124; resultSet= &#124;
&#124; meta=getMetaData &#124;
&#124; meta=.getColumnCount &#124; &#124; 2 &#124;
&#124; next &#124;
&#124; getInt &#124; age &#124; &#124; 30 &#124;
&#124; getString &#124; title &#124; &#124; Sr Manager &#124;</pre>
</div>
<p>Save your changes. Click on properties and check the Test check-box to make FitNesse.OracleSuite.SelectQuery a test page. Click on "Save Properties".</p>
<p>Click on the Test button in top left menu to run your database query and view the results. Here in above test I am expecting result of select query to be 30, Sr Manager. FitNesse will mark these 2 cells green or red depending upon the actual query results.</p>
<p>Even though I took Oracle as database in my example above but Generic Fixture is not tied with any database. You can drop the jar file of any JDBC driver and set the classpath as instructed above to test any database. I have personally used Oracle, Sybase and MySQL in my testing without any problems.</p>
<p>So you can see how easy it is to do database testing using Generic Fixture <b>without ever writing a single line of Java code</b>.</p>
</div>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Use of variables, arrays and complex types in Generic Fixture]]></title>
<link>http://anubhava.wordpress.com/2008/01/28/use-of-variables-arrays-and-complex-types-in-generic-fixture/</link>
<pubDate>Sat, 12 Apr 2008 02:04:00 +0000</pubDate>
<dc:creator>anubhava</dc:creator>
<guid>http://anubhava.wordpress.com/2008/01/28/use-of-variables-arrays-and-complex-types-in-generic-fixture/</guid>
<description><![CDATA[Please visit Introducing FitNesse&#8217;s Generic Fixture for introductory details about Generic Fix]]></description>
<content:encoded><![CDATA[<div style="text-align:justify;">Please visit <a href="http://anubhava.wordpress.com/2008/02/09/introducing-generic-fixture-for-fitnesse/">Introducing FitNesse's Generic Fixture</a> for introductory details about Generic Fixture.Here we shall see how we can use variables in Generic Fixture.You can use a variable myVar in test tables like this to store return value of method1:<br />
<span style="color:#660000;">&#124; myVar=method1 &#124; arg1 &#124; arg2 &#124; &#124; returnValue &#124;</span><br />
....<br />
....<br />
or You can use a variable "params" in a test table like this to store the SUT (System Under Test, which is a HashMap here) itself:<br />
<span style="color:#660000;">!&#124; Generic Fixture &#124; params=java.util.HashMap &#124;<br />
&#124; put &#124; curr_id &#124; 128 &#124;<br />
&#124; size &#124; &#124; 1 &#124;<br />
&#124; toString &#124; &#124;<br />
</span><br />
and later to use this variable myVar in an argument list use this syntax:<br />
<span style="color:#660000;">&#124; method2 &#124; myVar= &#124; arg2 &#124; &#124; </span><span style="color:#660000;">returnValue </span><span style="color:#660000;">&#124;</span><br />
....<br />
or to use this variable myVar in return value use this syntax:<br />
<span style="color:#660000;">&#124; method3 &#124; arg1 &#124; &#124; myVar= &#124;</span><br />
....<br />
or You can even use this variable myVar to instantiate a new class, use this syntax:<br />
<span style="color:#660000;">!&#124; Generic Fixture &#124; myClass &#124; myVar= &#124;</span><br />
....<br />
Or you can even use this variable myVar in a new table as SUT WITHOUT a new instantiation. In this case GenericFixture starts a new test table with the class type derived from the type of the variable itself. After that you are free to call all the available methods in the class type of myVar. Use this syntax:<br />
<span style="color:#660000;">!&#124; Generic Fixture &#124; myVar= &#124;</span><br />
....myVar=method call will store method's return value in variable named "myVar". And subsequent myVar= will populate the stored value.There is a <span style="font-weight:bold;">special variable named "this"</span>, that will mean assigning a new value to the <strong>System Under Test (SUT)</strong> object itself.Variables in Generic Fixture can store any Java object or primitive type, that included arrays also. To re-use the varialbe "params" we used above for storing HashMap in a new table just write this:<br />
<span style="color:#660000;">!&#124; Generic Fixture &#124; params= &#124;<br />
&#124; size &#124; &#124; 1 &#124;<br />
&#124; toString &#124; &#124;</span></p>
<p>Now lets take a look at another example:</p>
<div style="border:1px dashed black;background-color:rgb(249, 249, 249);text-align:left;font-size:0.85em;padding:5px;">
<pre>!&#124; Generic Fixture &#124; Address &#124; 123 &#124; Nutley Street &#124; New York &#124; 21019 &#124; NY &#124;
&#124; getStreetNo &#124; &#124; 123 &#124;
&#124; getCity &#124; &#124; New York &#124;
&#124; state=getState &#124; &#124; NY &#124;
&#124; getFullAddress &#124; &#124; 123 Nutley Street, New York, NY - 21019 &#124;
&#124; setStreetNo &#124; 111 &#124;
&#124; setPostcode &#124; 20133 &#124;
&#124; getPostcode &#124; &#124; 20133 &#124;
&#124; getStreetNo &#124; &#124; 111 &#124;
&#124; getState &#124; &#124; state= &#124;
&#124; setName &#124; John Smith &#124;
&#124; name=getName &#124; &#124; John Smith &#124;

!&#124; Generic Fixture &#124; Address$Name &#124; name= &#124;
&#124; getSurname &#124; &#124; Smith &#124;
&#124; getFirstname &#124; &#124; John &#124;
&#124; toString &#124; &#124; John Smith &#124;

!&#124; Generic Fixture &#124; name= &#124;
&#124; getSurname &#124; &#124; Smith &#124;
&#124; getFirstname &#124; &#124; John &#124;
&#124; toString &#124; &#124; John Smith &#124;</pre>
</div>
<p>Here first I am storing return value of getState() (String type) in a variable "state" and later using state to compare return value of getState in the test.</p>
<p>We are also using another variable called "name" to store return value of getName() which is of Address$Name type. We are using variable "name" in the constructor of a new new table that operates on Address$Name class. And in the 3rd table we are once again using variable "name" without instantiating a new class by marking variable "name" as SUT.</p>
<p>These examples show how variables can be used to store all standard Java as well as user defined objects.</p>
<p>Code for class Address and inner Address$Name is attached here for reference:</p>
<p><b>Source Code Address.java</b></p>
<div style="border:1px dashed black;background-color:rgb(249, 249, 249);text-align:left;font-size:0.85em;padding:5px;">
<pre>public class Address {
 public static class Name {
    private String surname = null;
    private String firstname = null;       

    public Name() {
    }       

    public Name(Name n) {
       this.surname = n.surname;
       this.firstname = n.firstname;
    }       

    public static Object parse(String s) {
       Name n = new Name();
       String[] arr = s.split(" ");
       if (arr.length == 2) {
          n.setFirstname(arr[0]);
          n.setSurname(arr[1]);
       }
       return n;
    }       

    @Override
    public String toString() {
       return this.firstname + " " + this.surname;
    }       

    public String getSurname() {
       return surname;
    }       

    public void setSurname(String surname) {
       this.surname = surname;
    }       

    public String getFirstname() {
       return firstname;
    }       

    public void setFirstname(String firstname) {
       this.firstname = firstname;
    }
 }       

 private int streetNo = 0;
 private String street = null;
 private String city = null;
 private int postcode = 0;
 private String state = null;
 private Name name = null;       

 public Address() {
    super();
 }       

 public Address(Integer streetNo, String street, String city, int postcode,
       String state) {
    super();
    setAddress(streetNo, street, city, postcode, state);
 }       

 public void setAddress(Integer streetNo, String street, String city,
       int postcode, String state) {
    this.streetNo = streetNo.intValue();
    this.street = street;
    this.city = city;
    this.postcode = postcode;
    this.state = state;
 }       

 public void setStreetNo(Integer streetNo) {
    this.streetNo = streetNo;
 }       

 public Integer getStreetNo() {
    return this.streetNo;
 }       

 public String getStreet() {
    return this.street;
 }       

 public void setCity(String city) {
    this.city = city;
 }       

 public String getCity() {
    return this.city;
 }       

 public void setPostcode(int postcode) {
    this.postcode = postcode;
 }       

 public int getPostcode() {
    return this.postcode;
 }       

 public String getFullAddress() {
    return this.streetNo + " " + this.street + ", " + this.city + ", "
          + this.state + " - " + this.postcode;
 }       

 public void setStreet(String street) {
    this.street = street;
 }       

 public String getState() {
    return state;
 }       

 public void setState(String state) {
    this.state = state;
 }       

 public Name getName() {
    return name;
 }       

 public void setName(Name name) {
    this.name = name;
 }
}</pre>
</div>
<p style="text-align:justify;"><span style="font-weight:bold;">How to input Array parameter:</span> Simply start the value with array: suffix and use delimiter comma ',' to separate out items in array. For example array:G,e,n,e,r,i,c,F,i,x,t,u,r,e means an array of characters or array:1,4,9,16,25 means an array of integers.</p>
<p style="text-align:justify;">Let's take a look at another example where simple type, this type and array type variables are being used.</p>
<div style="border:1px dashed black;background-color:rgb(249, 249, 249);text-align:left;font-size:0.85em;padding:5px;">
<pre>!&#124; Generic Fixture &#124; java.lang.String &#124; It's a cool fixture &#124;
&#124; toString &#124; &#124;
&#124; i=indexOf &#124; cool &#124; &#124; 7 &#124;
&#124; this=concat &#124; ; indeed &#124; &#124; It's a cool fixture; indeed &#124;
&#124; equals &#124; It's a cool fixture; indeed &#124; &#124; true &#124;
&#124; equalsIgnoreCase &#124; blank &#124; &#124; false &#124;
&#124; str=concat &#124; blank &#124; &#124; It's a cool fixture; indeed &#124;
&#124; equals &#124; str= &#124; &#124; true &#124;
&#124; matches &#124; ^.*cool fix.*$ &#124; &#124; true &#124;
&#124; indexOf &#124; cool &#124; &#124; i= &#124;
&#124; arr=toCharArray &#124; &#124;
&#124; concat &#124; !!! &#124; &#124; It's a cool fixture; indeed !!! &#124;        

!&#124; Generic Fixture &#124; java.lang.String &#124; arr= &#124;
&#124; toString &#124; &#124; str= &#124;
&#124; toCharArray &#124; &#124; arr= &#124;        

!&#124; Generic Fixture &#124; java.lang.String &#124; str= &#124;
&#124; toString &#124; &#124; str= &#124;
&#124; toCharArray &#124; &#124; arr= &#124;       

!&#124; Generic Fixture &#124; java.lang.String &#124; array:G,e,n,e,r,i,c,F,i,x,t,u,r,e &#124;
&#124; toString &#124; &#124; GenericFixture &#124;
&#124; toCharArray &#124; &#124; G,e,n,e,r,i,c,F,i,x,t,u,r,e &#124;       

!&#124; Generic Fixture &#124; java.lang.Math &#124;
&#124; abs &#124; i= &#124; &#124; 7 &#124;</pre>
</div>
<p style="text-align:justify;">You can see how I am using this to overwrite the value of the object itself on which all the methods are being executed. Execution of above test will produce below result. Note how actual value of a variable is appended in the result. Also note the use of array type variable "arr" in various operations.</p>
<p style="text-align:justify;"><a href="http://bp1.blogger.com/_eeszVwJCXvs/R56nmdscqwI/AAAAAAAAAy0/qrZiVh1ASDo/s1600-h/string-result.JPG"><img style="cursor:pointer;" src="http://bp1.blogger.com/_eeszVwJCXvs/R56nmdscqwI/AAAAAAAAAy0/qrZiVh1ASDo/s320/string-result.JPG" border="0" alt="" /></a></p>
<p><b>UPDATE: </b><br />
Added support of in-table variable.method() invocation. eg: if you already have a return value stored in a variable called "myvar" then calling a method foo() on myvar is now allowed in the same test table. Just use following syntax:<br />
&#124; myvar.foo &#124; arg1 &#124; arg2 &#124; &#124; ret &#124;<br />
Take a look at this example:</p>
<div style="border:1px dashed black;background-color:rgb(249, 249, 249);text-align:left;font-size:0.85em;padding:5px;">
<pre>!&#124; Generic Fixture &#124; java.lang.String &#124; It's a cool fixture &#124;
&#124; toString &#124; &#124;
&#124; i=indexOf &#124; cool &#124; &#124; 7 &#124;
&#124; this=concat &#124; ; indeed &#124; &#124; It's a cool fixture; indeed &#124;
&#124; equals &#124; It's a cool fixture; indeed &#124; &#124; true &#124;
&#124; equalsIgnoreCase &#124; blank &#124; &#124; false &#124;
&#124; str=concat &#124; blank &#124; &#124; It's a cool fixture; indeed &#124;
&#124; equals &#124; str= &#124; &#124; true &#124;
&#124; str=.substring &#124; 21 &#124; &#124; indeed &#124;
&#124; matches &#124; ^.*cool fix.*$ &#124; &#124; true &#124;
&#124; indexOf &#124; cool &#124; &#124; i= &#124;
&#124; arr=toCharArray &#124; &#124;
&#124; concat &#124; !-&#160;!!!-! &#124; &#124; It's a cool fixture; indeed !!! &#124;
&#124; substring &#124; 3 &#124; &#124;
&#124; str=.toCharArray &#124; &#124; arr= &#124;
</pre>
</div>
<p>Note how this test table is using variable "str" to store original string and then calling methods directly on variable "str" using <b>str=.substring</b> and <b>str=.toCharArray</b> calls. You can even do <b>substr=str=.substring</b> to create another variable "substr" to store return value of <b>str=.substring</b> call.
</div>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Introducing DSL Adapter for Generic Fixture]]></title>
<link>http://anubhava.wordpress.com/?p=18</link>
<pubDate>Thu, 27 Mar 2008 03:25:04 +0000</pubDate>
<dc:creator>anubhava</dc:creator>
<guid>http://anubhava.wordpress.com/?p=18</guid>
<description><![CDATA[
DSL (Domain Specific Language) is used to define problems in a specific domain. DSL, off late has g]]></description>
<content:encoded><![CDATA[<div style="text-align:justify;">
<div><b>DSL (Domain Specific Language)</b> is used to define problems in a specific domain. DSL, off late has gained a lot of focus due to its readability and ease of use. It is much more expressive than general purpose programming language especially for test authors, business people and end users.</div>
<div>&#160;</div>
<div>When I published my <a href="http://anubhava.wordpress.com/2008/02/09/introducing-generic-fixture-for-fitnesse/" target="ext">Generic Fixture</a>, there was a very valid concern raised by some FitNesse users that since <a href="http://anubhava.wordpress.com/2008/02/09/introducing-generic-fixture-for-fitnesse/" target="ext">Generic Fixture</a> lets testers write their tests without writing any Java code and exposes user’s class level details (such as constructors and methods) to testers it might not be very appealing to customer and business folks as it is to developers. That’s when I started dwelling into this issue. Initially I thought of providing a MS Excel macro that lets testers write their test in DSL and by running that macro it will produce class level tests suited for Generic Fixture. But I abandoned that macro idea because of my unfamiliarity with VB and also to avoid hassle of an extra step for testers. (what if testers are writing tests directly on Wiki page rather than MS Excel). Finally I decided upon providing a plug-in kind of extension to <a href="http://anubhava.wordpress.com/2008/02/09/introducing-generic-fixture-for-fitnesse/" target="ext">Generic Fixture</a> that will let testers define their own high level customer centric language (DSL). This DSL adapter will contain information on how to map it to Java Class level details. They just have to define this mapping once for each domain and can make it part of the SetUp page to make it available to for all the test pages.</div>
<div>&#160;</div>
<div>There are many advantages of defining DSL in the test tables itself over the defining DSL inside the Java code. How powerful a DSL will be which is being created by a developer rather than the end-user himself? Doesn’t it loose the very concept of being a customer centric language? Advantage of DSL is its user friendly nature or being a customer centric language. But we all know that each customer or end user is different. What if the verbalization or syntax of DSL preferred by one user is not liked by another user. By writing DSL through source code we are saying this is the language better adapt to it and it <b>CANNOT</b> be changed. But my approach of defining DSL in the test tables gives you this flexibility. You can alter or modify DSL for each user and that too on the fly and at will, without ever making any source code change. Using this approach, DSL can be modified and managed directly by the customers, they can write tests in <b>ANY LANGUAGE</b> not just in English. That goes along with the goal of the <a href="http://anubhava.wordpress.com/2008/02/09/introducing-generic-fixture-for-fitnesse/" target="ext">Generic Fixture</a> that the testers should be able to write tests without writing source code.</div>
<div>&#160;</div>
<p><b>Syntax of defining DSL</b>: It is basically a mapping of DSL and Java method calls. All of your DSL mappings will be in a FitNesse table with DSLAdapter as the class name, appearing in first column of the first row</p>
<p>Basic Syntax is: <b>DSL follwed by Actual Java Method call</b></p>
<p>Each argument to DSL &#38; Java method appears in a separate table cell. All arguments of DSL appear as %. All the arguments to a Java method call are defined as positional parameters of DSL such as {1}, {2},...{n} delimited by comma character ",".</p>
<p>So for a method called max(arg1, arg2) if you want to define a DSL such as "get the max of 2 numbers num1 and num2" then it would look like this:</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:0.85em;padding:5px;">
<pre>!&#124; DSL Adapter &#124;
&#124; get the max of 2 numbers &#124; % &#124; and &#124; % &#124; max &#124; {1}, {2} &#124;</pre>
</div>
<p>% is just a place holder over here for arguments and {1} is the first argument in DSL and {2} is second parameter in DSL. Once defined now to use this DSL in writing tests simply write this:</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:0.85em;padding:5px;">
<pre>&#124; get the max of 2 numbers &#124; 25 &#124; and &#124; 28 &#124; &#124;</pre>
</div>
<p>Once you take a look at some more examples it will be much more clear how to create and modify your own DSL.</p>
<p>Let’s take a look at some more <b>examples</b>:</p>
<p>While writing web tests using Selenium there often is a need for pausing the test for 1 or 2 sec to let Selenium do frame loading (esp needed in Frames based testing where main page has loaded but some iframe still needs time to load). Selenium doesn't have a pause method and ONLY way to pause it is by calling <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#sleep%28long%29" target="ext">sleep(long ms)</a> method in <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html" target="ext">java.lang.Thread</a>. Testers can simple write: &#124; java.lang.Thread.sleep &#124; 2000 &#124; to get 2 second pause but since it is a pure Java call and sometimes too technical for test authors it is better to define a DSL for that using following syntax:</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:0.85em;padding:5px;">
<pre>!&#124; DSL Adapter &#124;
&#124; pause the test for &#124; % &#124; seconds &#124; java.lang.Thread.sleep &#124; {1}000 &#124;</pre>
</div>
<p>Having defined this DSL now test authors will just need to write this in their web tests:</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:0.85em;padding:5px;">
<pre>&#124; pause the test for &#124; 2 &#124; seconds &#124;</pre>
</div>
<p>which is much more readable and user friendly.</p>
<p>Now lets take a look at my DSL for Selenium API. Define this DSL in a SetUp page to make it available for all the test pages.</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:0.85em;padding:5px;">
<pre>!&#124; DSL Adapter &#124;
&#124; user starts the browser &#124; start &#124; &#124;
&#124; user opens the URL &#124; % &#124; open &#124; {1} &#124;
&#124; page has the title &#124; getTitle &#124; &#124;
&#124; user types &#124; % &#124; into &#124; % &#124; field &#124; type &#124; {2}, {1} &#124;
&#124; user sees the text on the page &#124; % &#124; isTextPresent &#124; {1} &#124;
&#124; page has an element named &#124; % &#124; isElementPresent &#124; {1} &#124;
&#124; page loads in less than &#124; % &#124; seconds &#124; waitForPageToLoad &#124; {1}000 &#124;
&#124; page has URL &#124; getLocation &#124; &#124;
&#124; user clicks on the submit button &#124; click &#124; //button[@type='submit'] &#124;
&#124; user clicks on the link named &#124; % &#124; click &#124; link={1} &#124;
&#124; user clicks on the button named &#124; % &#124; clickAt &#124; {1},"" &#124;
&#124; get text from element named &#124; % &#124; getText &#124; xpath=id('{1}') &#124;
&#124; get xpath text from address &#124; % &#124; getText &#124; xpath={1} &#124;
&#124; user removes the cookie named &#124; % &#124; at path &#124; % &#124; deleteCookie &#124; {1}, {2} &#124;
&#124; user selects an option &#124; % &#124; from the drop-down &#124; % &#124; select &#124; {2}, label={1} &#124;
&#124; pause the test for &#124; % &#124; seconds &#124; java.lang.Thread.sleep &#124; {1}000 &#124;
&#124; user stops the browser &#124; stop &#124; &#124;</pre>
</div>
<p>Using above DSL my Google web test will look like this. First add this test table to start Selenium test in SetUp page:</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:0.85em;padding:5px;">
<pre>!define ds {com.thoughtworks.selenium.DefaultSelenium}
!define site {http://www.google.com}
!&#124; Generic Fixture &#124; selenium=${ds} &#124; localhost &#124; 4444 &#124; *pifirefox &#124; ${site} &#124;
&#124; user starts the browser &#124;</pre>
</div>
<p>And write this test table in your main test page GoogleTest:</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:0.85em;padding:5px;">
<pre>!define q {fitnesse generic fixture}
!&#124; Generic Fixture &#124; selenium= &#124;
&#124; user opens the URL &#124; http://www.google.com &#124;
&#124; page has the title &#124; &#124; Google &#124;
&#124; page has an element named &#124; q &#124; &#124; true &#124;
&#124; page has an element named &#124; btnG &#124; &#124; true &#124;
&#124; user types &#124; ${q} &#124; into &#124; q &#124; field &#124;
&#124; user clicks on the button named &#124; btnG &#124;
&#124; page loads in less than &#124; 5 &#124; seconds &#124;
&#124; page has the title &#124; &#124; ${q} - Google Search &#124;
&#124; user clicks on the link named &#124; Next &#124;
&#124; page loads in less than &#124; 5 &#124; seconds &#124;
&#124; user clicks on the link named &#124; Next &#124;
&#124; page loads in less than &#124; 5 &#124; seconds &#124;
&#124; user sees the text on the page &#124; Results 21 - 30 &#124; &#124; true &#124;</pre>
</div>
<p>and finally this small test table in TearDown page to stop the Selenium test:</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:0.85em;padding:5px;">
<pre>!&#124; Generic Fixture &#124; selenium= &#124;
&#124; user stops the browser &#124;</pre>
</div>
<p>Few important things to be noted here are:</p>
<ol>
<li>A new instance of Selenium is being created in SetUp page and being used in main page and TearDown page using a variable selenium=.</li>
<li>By using a variable to store Selenium instance and reusing it, you can move common initialization code in SetUp and common cleanup code in TearDown page. Also it will make sure that in the event of an exception being thrown (and that may happen often in web testing) your cleanup (TearDown page) will ALWAYS be called.</li>
<li>Test tables are not calling any of the Selenium APIs, only DSL is being used to direct Selenium run all the test steps.</li>
<li>Even though Selenium's waitForPageToLoad method expects you to pass milli seconds, using DSL we pass seconds value only by appending 000 in the argument. Using this approach you can always hide the complexity of the method arguments from the test authors.</li>
<li>Customizing this DSL is super easy. Lets say some user doesn't like the text user opens the URL and wants <b>user opens a page</b> instead. In that case just go to the above FitNesse's SetUp page and edit the table that starts with DSL Adapter and replace the text so it will become like this:<br />
<b>&#124; user opens a page &#124; http://www.google.com &#124;</b></li>
<li>If the underlying class (Selenium in this case) adds some new APIs with its new release, any other Fixture implementation approach would require a corresponding code change and new release. Whereas this DSL adapter just needs couple of new lines in a FitNesse SetUp page to define new "mapping" between DSL and new API calls.</li>
</ol>
</div>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Testing EJBs using Generic Fixture]]></title>
<link>http://anubhava.wordpress.com/?p=17</link>
<pubDate>Sat, 15 Mar 2008 19:55:46 +0000</pubDate>
<dc:creator>anubhava</dc:creator>
<guid>http://anubhava.wordpress.com/?p=17</guid>
<description><![CDATA[As I have mentioned in my Introduction to Generic Fixture post that we can use Generic Fixture to wr]]></description>
<content:encoded><![CDATA[<p>As I have mentioned in my <a href="http://anubhava.wordpress.com/2008/02/09/introducing-generic-fixture-for-fitnesse/">Introduction to Generic Fixture</a> post that we can use Generic Fixture to write acceptance tests to validate almost any type of Java application. In my previous post I demonstrated how to make use of Generic Fixture to write automated web tests. Let's now see how to use Generic Fixture for testing an EJB (Enterprise Java Bean).</p>
<p>Here is a sample Java code of a typical EJB client. Any Java developer who has ever written code to call EJBs will be well aware of following Java code snippet.</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:90%;padding:5px;">
<pre>import javax.naming.InitialContext;
import javax.naming.Context ;
import com.sales.Product.*;public void TestPrice() {
   try
   {
      // create and load properties
      Properties props = new Properties();
      props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
      props.put(Context.PROVIDER_URL, "t3://localhost:7001");

      // get initial context using loaded properties
      InitialContext context = new InitialContext(props);

       // JNDI lookup
      Object jndi = context.lookup("ProductHome");

       // narrow down remote object to get remote home
      ProductHome home = (ProductHome) javax.rmi.PortableRemoteObject.narrow(jndi,
                                   ProductHome.class);

      // create service from remote home
      ProductService productService = home.create();

      // check if Product IDs exist in Database
      boolean result1 = productService.isValid(1801);
      boolean result1 = productService.isValid(9999);

      // assert our results
      assertEquals( result1, true );
      assertEquals( result2, false );
   }
   catch (Exception ex)
   {
       ex.printStactTrace();
   }
}</pre>
</div>
<p>This code is first trying to do a lookup for JNDI object "ProductHome" (remote home) deployed on a Weblogic application server. Upon a successful lookup it creates a service object from remote home and finally calls isValid(int) method on the service class.</p>
<p>Now let's see how are we going to implement this code in a FitNesse test table using Generic Fixture.</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:90%;padding:5px;">
<pre>!path weblogic.jar
!path productEjbs.jar

'''Set debug ON for Generic Fixture'''
!&#124; Generic Fixture &#124; Generic Fixture &#124;
&#124; set debug &#124; true &#124;'''Load the required properties'''
!&#124; Generic Fixture &#124; props=java.util.Properties &#124;
&#124; put &#124; javax.naming.Context.INITIAL_CONTEXT_FACTORY &#124; weblogic.jndi.WLInitialContextFactory &#124;
&#124; put &#124; javax.naming.Context.PROVIDER_URL &#124; t3://localhost:7001 &#124;
&#124; toString &#124; &#124;

'''Load the Remote Home class'''
!&#124; Generic Fixture &#124; java.lang.Class &#124;
&#124; homeClass=forName &#124; com.sales.Product.ProductHome &#124;

'''Lookup JNDI from Initial Context'''
!&#124; Generic Fixture &#124; javax.naming.InitialContext &#124; props= &#124;
&#124; jndi=lookup &#124; ProductHome &#124;
&#124; obj=javax.rmi.PortableRemoteObject.narrow &#124; jndi= &#124; homeClass= &#124;

'''Cast Narrowed object to Remote Home object'''
!&#124; Generic Fixture &#124; homeClass= &#124;
&#124; homeObj=cast &#124; obj= &#124;

'''Create service object from remote home object'''
!&#124; Generic Fixture &#124; homeObj= &#124;
&#124; service=create &#124;

'''Check if given Product IDs exist in Database'''
!&#124; Generic Fixture &#124; service= &#124;
&#124; isValid &#124; 1801 &#124; &#124; true &#124;
&#124; isValid &#124; 7000 &#124; &#124; false &#124;</pre>
</div>
<p>Since we had to operate on multiple objects and classes, we have heavily used the <a href="http://anubhava.wordpress.com/2008/02/08/use-of-variables-arrays-and-complex-types-in-generic-fixture/">variables feature</a> of Generic Fixture. Most of the test code is self explanatory with the comments provided on top of each table. Only tricky thing is to call <b>Class.Cast(Object)</b> method to get the casting right for <b>ProductHome home = (ProductHome) javax.rmi.PortableRemoteObject.narrow(jndi, ProductHome.class)</b> call in Java code.</p>
<p>Go ahead and give it a try.</p>
<p>So using Generic Fixture we <u><b>completely eliminated the need to write Java code</b></u> given in above section to test our ProductHome EJB. Writing EJB test in Generic Fixture of course has huge advantage over writing Java code. These test tables can be altered by any non-developer. For ex: if there is a new requirement to test validity of Product ID: 5319 then it is as simple as adding this line in the last table:</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:90%;padding:5px;">
<pre>&#124; isValid &#124; 5319 &#124; &#124; true &#124;</pre>
</div>
<p>Which is much easier than finding a developer to change and re-compile the Java code.</p>
<p>I intentionally chose a simple operation on ProductHome EJB here to pass on the idea but almost any operation on EJBs can be performed using this approach, thus giving us the ability to build really robust and useful acceptance tests without writing any Java code.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Jump Start FitNesse with Selenium using Generic Fixture]]></title>
<link>http://anubhava.wordpress.com/?p=15</link>
<pubDate>Mon, 10 Mar 2008 00:07:25 +0000</pubDate>
<dc:creator>anubhava</dc:creator>
<guid>http://anubhava.wordpress.com/?p=15</guid>
<description><![CDATA[Download FitNesse
Go to http://fitnesse.org/FitNesse.DownLoad and download the the &#8220;Full Distr]]></description>
<content:encoded><![CDATA[<h3>Download FitNesse</h3>
<p>Go to <a href="http://fitnesse.org/FitNesse.DownLoad" target="ext">http://fitnesse.org/FitNesse.DownLoad</a> and download the the "Full Distribution (fitnesse200#####.zip)". Unpack the zip into c:\program files. Once extracted you must have a directory c:\program files\fitnesse.</p>
<h3>Download Selenium Remote Control</h3>
<p>Go to <a href="http://selenium-rc.openqa.org/download.jsp" target="ext">http://selenium-rc.openqa.org/download.jsp</a> and download the latest version (1.0-beta-1 at the time of writing this page). Unpack the zip into c:\program files. Once extracted you must have a directory c:\program files\selenium. Current version for Selenium-RC is 1.0-beta-1 and these instructions are written assuming you are using this version.</p>
<h3>Create a smart start script</h3>
<p>Copy and paste following script into a file called run.vbs under the directory "C:\Program Files\selenium\selenium-remote-control-1.0-beta-1\selenium-server-1.0-beta-1". This script will start both FitNesse servers and Selenium remote control servers on their default ports 8000 and 4444 respectively. This script will <strong>ONLY</strong> start these processes if these processes are not running, so this script can be safely run any time.</p>
<p><strong>PS:</strong> Please note that this script is starting Selenium in an experimental <a href="http://selenium-rc.openqa.org/options.html" target="ext">Proxy Injection Mode</a> which lets you run your web test across multiple domains. If you don't want to use this feature feel free to change this start script.</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:0.85em;padding:2px;">
<pre>Function IsProcessRunning( strServer, strProcess )
   Dim Process, strObject
   IsProcessRunning = False
   strObject   = "winmgmts://" &#38; strServer
   For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
       If UCase( Process.name ) = UCase( strProcess ) Then
           IsProcessRunning = True
           Exit Function
       End If
   Next
End Function

sServer = "."      ' "." for local machine
Set objShell = WScript.CreateObject("WScript.Shell")
Set objEnv = objShell.Environment("Process")

FitNesse = "java -cp fitnesse.jar fitnesse.FitNesse -p 8000"
If( IsProcessRunning( sServer, FitNesse ) = False ) Then
   objshell.CurrentDirectory  = "C:\program files\fitnesse"
   f = objshell.Run  ( FitNesse, 6, false )
End If

Selenium = "java -jar selenium-server.jar -browserSessionReuse -proxyInjectionMode"
If( IsProcessRunning( sServer, Selenium ) = False ) Then
   objshell.CurrentDirectory = _
"C:\program files\selenium\selenium-remote-control-1.0-beta-1\selenium-server-1.0-beta-1"
   result = objshell.Run  ( Selenium, 5, true )
End If

Wscript.Quit</pre>
</div>
<h3>Download and Install Generic Fixture</h3>
<p>Just follow simple instructions at <a href="http://anubhava.wordpress.com/2008/02/09/download-and-install-instructions/" target="ext">this page</a> or just drop <a href="http://genericfixture.wiki.sourceforge.net/space/showimage/genericfixture.jar" target="external">genericfixture.jar</a> into "C:\Program Files\fitnesse" directory.<br />
Copy selenium-java-client-driver.jar from "C:\program files\selenium\selenium-remote-control-1.0-beta-1\selenium-java-client-driver-1.0-beta-1" to "C:\program files\fitnesse" directory.</p>
<h3>Run startup script</h3>
<p>Using Windows explorer go to the directory "C:\Program Files\selenium\selenium-remote-control-1.0-beta-1\selenium-server-1.0-beta-1" and double click on the run.vbs. This will start 2 Java process in 2 separate command windows with Selenium window in normal and FitNesse window in minimized state.</p>
<h3>Create a page on FitNesse for Google Web Test using Generic Fixture</h3>
<ol>
<li>Open your browser and goto the URL <a href="http://localhost:8000/FrontPage" target="ext">http://localhost:8000/FrontPage.</a> Look for the Edit button on the left hand navigation column. If Edit button is not present then goto the URL <a href="http://localhost:8000/FrontPage?properties" target="ext">http://localhost:8000/FrontPage?properties</a> and select the <strong>"Edit"</strong> check box and click on Save Properties. Now click on Edit button and once on the Edit Page add a new line at the end of all the text already there and save your changes.
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:0.85em;padding:5px;">
<pre>&#124;[[Web Test Suites][FitNesse.SuiteWebTests]]&#124;FitNesse's suite of Web Tests&#124;</pre>
</div>
</li>
<li>Now on the Front Page it will display a text like <strong>"Web Test Suites?"</strong> with ? as hyper link. Click on ? link.</li>
<li>Once in the Edit Page copy paste following text into text area and save your changes:
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:0.85em;padding:5px;">
<pre>!*&#62; Class Path &#38; Global Defines
!path selenium-java-client-driver.jar
!path genericfixture.jar
!define IE {*piiexplore}
!define FF {*pifirefox}
!define sel {selenium=}
!define ds {com.thoughtworks.selenium.DefaultSelenium}
!define host {localhost}
!define port {4444}
!define COLLAPSE_SETUP {true}
!define COLLAPSE_TEARDOWN {true}
*!
----
SuiteWebTests.SetUp
SuiteWebTests.TearDown
SuiteWebTests.GoogleTest</pre>
</div>
</li>
<li>You will notice 3 ? links on the page. Now lets create each and every missing page.</li>
<li>Click on the ? link next to SuiteWebTests.SetUp text and on the "Edit Page" text area copy-paste following code an save your changes.
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:0.85em;padding:5px;">
<pre>!&#124; DSL Adapter &#124;
&#124; user types &#124; % &#124; into &#124; % &#124; field &#124; type &#124; {2}, {1} &#124;
&#124; user starts the browser &#124; start &#124; &#124;
&#124; users opens the URL &#124; % &#124; open &#124; {1} &#124;
&#124; page has the title &#124; getTitle &#124; &#124;
&#124; user sees the text on the page &#124; % &#124; isTextPresent &#124; {1} &#124;
&#124; page has an element named &#124; % &#124; isElementPresent &#124; {1} &#124;
&#124; page loads in less than &#124; % &#124; seconds &#124; waitForPageToLoad &#124; {1}000 &#124;
&#124; page has URL &#124; getLocation &#124; &#124;
&#124; user clicks on submit button &#124; click &#124; //button[@type='submit'] &#124;
&#124; user clicks on the link named &#124; % &#124; click &#124; link={1} &#124;
&#124; user clicks on the button named &#124; % &#124; clickAt &#124; {1},"" &#124;
&#124; get text from element named &#124; % &#124; getText &#124; xpath=id('{1}') &#124;
&#124; user stops the browser &#124; stop &#124; &#124;
&#124; add a key-value with key &#124; % &#124; and value &#124; % &#124; put &#124; {1}, {2} &#124;
&#124; get value for the key &#124; % &#124; get &#124; {1} &#124;
&#124; show &#124; toString &#124; &#124;

!&#124;Generic Fixture&#124;${sel}{ds}&#124;${host}&#124;${port}&#124;${FF}&#124;http://${host}&#124;
&#124; user starts the browser &#124;</pre>
</div>
</li>
<li>Go back to the page: <a href="http://localhost:8000/FitNesse.SuiteWebTests" target="ext">http://localhost:8000/FitNesse.SuiteWebTests</a></li>
<li>Click on the ? link next to SuiteWebTests.TearDown text and on the "Edit Page" text area copy-paste following code an save your changes.
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:0.85em;padding:5px;">
<pre>!&#124; Generic Fixture &#124; ${sel} &#124;
&#124; user stops the browser &#124;</pre>
</div>
</li>
<li>Again go back to the page: <a href="http://lko.office.aol.com:8000/FitNesse.SuiteWebTests" target="ext">http://localhost:8000/FitNesse.SuiteWebTests</a></li>
<li>Now click on ? link next to SuiteWebTests.GoogleTest text and on the "Edit Page" text area copy-paste following code an save your changes.
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:0.85em;padding:5px;">
<pre>!define q {fitnesse generic fixture}
!&#124; Generic Fixture &#124; ${sel} &#124;
&#124; users opens the URL &#124; http://www.google.com &#124;
&#124; page has the title &#124; &#124; Google &#124;
&#124; page has an element named &#124; q &#124; &#124; true &#124;
&#124; page has an element named &#124; btnG &#124; &#124; true &#124;
&#124; user types &#124; ${q} &#124; into &#124; q &#124; field &#124;
&#124; user clicks on the button named &#124; btnG &#124;
&#124; page loads in less than &#124; 5 &#124; seconds &#124;
&#124; page has the title &#124; &#124; ${q} - Google Search &#124;
&#124; user clicks on the link named &#124; Next &#124;
&#124; page loads in less than &#124; 5 &#124; seconds &#124;
&#124; user clicks on the link named &#124; Next &#124;
&#124; page loads in less than &#124; 5 &#124; seconds &#124;
&#124; user sees the text on the page &#124; Results 21 - 30 &#124; &#124; true &#124;</pre>
</div>
</li>
<li>After saving your changes click on Properties button from the left hand navigation menu and click on check box left to Test property and save your changes. Now you should see <strong>Test</strong> button on the top of the lest navigation menu.</li>
</ol>
<h3>Execute your Google Web Test Page on FitNesse using Selenium</h3>
<p>Just click on the Test click on this page: <a href="http://localhost:8000/FitNesse.SuiteWebTests.GoogleTest" target="ext">http://localhost:8000/FitNesse.SuiteWebTests.GoogleTest</a> and watch the magic of web test being run. Test will open a new Firefox browser and go to www.google.com and search Google with query text "fitnesse generic fixture"<br />
Upon completion of test you should see this on the top of the results page:</p>
<p><strong>Assertions:</strong> 5 right, 0 wrong, 0 ignored, 0 exceptions</p>
<h3>Optional but Recommended Installations</h3>
<p>You are all set to to write your test tables in FitNesse.</p>
<p>However if you are doing web testing using Selenium, there are two very handy add-ons for Firefox that will be extremely useful for writing web tests:</p>
<ol>
<li>XPath Checker: Download it from <a href="https://addons.mozilla.org/en-US/firefox/addon/1095" target="ext">https://addons.mozilla.org/en-US/firefox/addon/1095</a></li>
<li>Selenium IDE: Download it from <a href="http://selenium-ide.openqa.org/download.jsp" target="ext">http://selenium-ide.openqa.org/download.jsp</a></li>
</ol>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Introducing Generic Fixture for FitNesse]]></title>
<link>http://anubhava.wordpress.com/2008/01/15/introducing-generic-fixture-for-fitnesse/</link>
<pubDate>Sun, 10 Feb 2008 01:58:00 +0000</pubDate>
<dc:creator>anubhava</dc:creator>
<guid>http://anubhava.wordpress.com/2008/01/15/introducing-generic-fixture-for-fitnesse/</guid>
<description><![CDATA[I have been using FitNesse (A wiki based integrated testing framework) for last 2 years to create au]]></description>
<content:encoded><![CDATA[<div style="text-align:justify;font-size:100%;color:#000000;font-family:verdana arial;text-decoration:none;">I have been using <a href="http://fitnesse.org/" target="_blank">FitNesse</a> (A wiki based integrated testing framework) for last 2 years to create automated integrated acceptance tests for my back end Java based and legacy C/C++ applications. It has helped us tremendously towards our efforts to adapt to <span style="font-weight:bold;">Test Driven Development </span>(TDD). FitNesse has really helped our development team to find &#38; fix bugs much earlier and our QA team to validate them pretty quickly. For beginners I will recommend reading the documentation on its official web site <a href="http://fitnesse.org/" target="_blank">http://fitnesse.org/</a> for information on downloading, installing and setting up FitNesse. FitNesse provides various "<a href="http://fitnesse.org/FitNesse.TestTableStyles" target="_blank">Test Table Styles</a>" (or fixtures) to write your tests. Each Table/Fixture Style has its own usage and purpose.</p>
<p>For testing business logic in my back end applications I mostly used ColumnFixture, TableFixture and RowFixture for defining inputs and output data sets. All I needed to write was a thin adapter or mapper Java class that extends any of these fixtures. That thin adapter Java class just gets input data from wiki and use that data to make a call to my back end application. At the end of the call it just makes the result available for FitNesse to display on wiki page. This thin adapter class is fully Fixture aware and developer of this class must know how to map data between back end application and FitNesse front end wiki page.</p>
<p>So far so good no major complains here, it worked great for us.</p>
<p>But I found this requirement to write the thin fixture adapter class for each new transaction a little annoying and have always toyed with the idea of building a generic Table/Fixture, one that <b><u>will not</u></b> require a developer to understand and be aware of the various fixtures coding conventions. In other words a fixture/table style where testers  can write acceptance tests without needing development support of writing fixture specific code for each new transaction.</p>
<p>That became the main driving force behind the thought of developing a Generic Fixture where you just drop your class in FitNesse's class path, write your test tables in wiki and be ready to test without having to write a single line of Java code. This idea is simple enough to understand but not so simple to implement because of the complexity of Java classes. Each class is different, it can have various type of constructors and methods (even overloaded ones). Each method can be returning different type of values (or not returning at all if method is void). We have to define some rules of defining class names, constructors, method names and their return types on wiki test tables first.</p>
<p>So here they are:</p>
<ol>
<li>Name of the class to test or system under test (SUT) and arguments to the SUT's constructor must come in a separate cell of the very first row of the table. (Starting from 2nd cell, since 1st cell is reserved for name of the Fixture Class itself). eg:<br />
<span style="color:#660000;">!&#124; Generic Fixture &#124; java.lang.String &#124; It's a cool fixture &#124;</span></li>
<li>Each row of the table will have a method name in the 1st cell followed by method parameters appearing each in a separate cell.</li>
<li>Leave an empty cell after end of parameters and start of return values. eg:<br />
<span style="color:#660000;">&#124; indexOf &#124; cool &#124; &#124; 7 &#124; &#124; concat &#124; !! &#124; &#124; It's a cool fixture!! &#124;</span></li>
<li>Class that is being tested can have methods accepting parameters of all primitive types (int, float, double etc) as well as of all the primitive Java wrapper classes (Integer, Double, String, Number Date etc).</li>
<li>If methods need to accept user defined object in parameters then those user defined types must provide a method: public static Object parse(String str) { ... }. An example of this is provided below in the Address class.</li>
<li>Methods with return types of all primitive types (int, float, double etc) as well as of all the primitive Java wrapper classes (Integer, Double, String, Number etc) should be supported.</li>
<li>Methods can also return array of all primitive types (int, float, double etc) as well as of all the primitive Java wrapper classes (Integer, Double, String, Number etc).</li>
<li>Class that is being tested can be a non-instantiating class like java.lang.Math. In this case all methods will be invoked statically.</li>
<li>Calls to static method must be allowed in the form of CanonicalClassName.MethodName eg:<br />
<span style="color:#660000;">&#124; java.lang.Thread.sleep &#124; 1000 &#124;</span></li>
<li>Should be able to operate with overloaded methods in a class. For example abs() method in java.lang.Math class:<br />
<span style="color:#660000;">&#124; abs &#124; -5.72 &#124; &#124; 5.72 &#124;</span></li>
<li>It should be able to store return value of a method into variables and a variable can be of any type. And later on this variable can be used anywhere in the test to pass a value, compare a return value, creating a new class or becoming a target itself. Please visit my other post <a href="/2008/02/08/use-of-variables-arrays-and-complex-types-in-generic-fixture/">Use of variables, arrays and complex types in Generic Fixture</a> for more details.</li>
</ol>
<p><b>Putting it all together:</b> Lets write a simple test table for testing <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html" target="_blank">java.lang.String</a> class. Lets say we have a Java code like this:</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:90%;padding:5px;"><code>java.lang.String aString = new java.lang.String ( "It's a cool fixture" );<br />
assertEquals ( aString.indexOf ( "cool"), 7 );<br />
assertEquals ( aString.concat ( ", indeed" ), "It’s a cool fixture, indeed" );<br />
assertEquals ( aString.compareTo ( "It’s a cool fixture" ), 0 );<br />
assertEquals ( aString.equalsIgnoreCase ( "" ), false );<br />
assertEquals ( aString.concat ( "" ), "It’s a cool fixture" );<br />
assertEquals ( aString.equals ( "" ), false );<br />
assertEquals ( aString.matches ( "^.*cool fix.*$" ), true );<br />
System.out.println ( aString.toCharArray () );</code></div>
<p>And here is the FitNesse equivalent of above Java code using Generic Fixture:</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:90%;padding:5px;"><code>!&#124; Generic Fixture &#124; java.lang.String &#124; It's a cool fixture &#124;<br />
&#124; indexOf &#124; cool &#124; &#124; 7 &#124;<br />
&#124; concat &#124; , indeed &#124; &#124; It's a cool fixture, indeed &#124;<br />
&#124; compareTo &#124; It's a cool fixture &#124; &#124; 0 &#124;<br />
&#124; equalsIgnoreCase &#124; blank &#124; &#124; false &#124;<br />
&#124; concat &#124; blank &#124; &#124; It's a cool fixture &#124;<br />
&#124; equals &#124; blank &#124; &#124; false &#124;<br />
&#124; matches &#124; ^.*cool fix.*$ &#124; &#124; true &#124;<br />
&#124; toCharArray &#124; &#124;</code></div>
<p><a href="http://anubhava.wordpress.com/2008/02/09/introducing-generic-fixture-for-fitnesse/address-test-results/" rel="attachment wp-att-10" title="Address Test Results"><img src="/files/addresstest.jpg" alt="Address Test Results" style="float:right;cursor:pointer;margin:0 0 0 10pt;" /></a>Click on Test button and you will get these results:<br />
<b>Assertions:</b> 7 right, 0 wrong, 0 ignored, 0 exceptions</p>
<p>In this test we tested <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html" target="_blank">java.lang.String</a> class and some of its methods. Notice last call in the test table above is String.toCharArray(), here we are not validating output of this call just getting output displayed. Nice thing is that we did not write any Java code for the String class we tested above. Looks pretty simple, isn't it?</p>
<p style="text-align:justify;">Let's write another test table for <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Math.html" target="_blank">java.lang.Math</a> class where all the methods are declared as static:</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:90%;padding:5px;"><code>!&#124; Generic Fixture &#124; java.lang.Math &#124;<br />
&#124; sqrt &#124; 25 &#124; &#124; 5.0 &#124;<br />
&#124; round &#124; 2.51 &#124; &#124; 3 &#124;<br />
&#124; max &#124; 3.469 &#124; 3.47 &#124; &#124; 3.47 &#124;<br />
&#124; java.lang.Thread.sleep &#124; 1000 &#124;<br />
&#124; abs &#124; -5.72 &#124; &#124; 5.72 &#124;<br />
</code></div>
<p>Click on Test button and you will get:</p>
<p><b>Assertions:</b> 4 right, 0 wrong, 0 ignored, 0 exceptions</p>
<p>Again this Generic fixture was able to do the magic behind the scene and run all the static methods of <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Math.html" target="_blank">java.lang.Math</a> class. Did you notice I am calling <span style="color:#990000;">&#124; java.lang.Thread.sleep &#124; 1000 &#124;</span> for introducing a delay of 1000 ms (1 sec) between max and abs method calls. This is the equivalent Java code for above fixture:</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:90%;padding:5px;"><code>assertEquals ( Math.sqrt ( 25 ), 5.0 );<br />
assertEquals ( Math.round ( 2.51 ), 3 );<br />
assertEquals ( Math.max ( 3.469, 3.47 ), 3.47 );<br />
java.lang.Thread.sleep ( 1000 );<br />
assertEquals ( Math.abs ( -5.72 ), 5.72 );</code></div>
<p>So far we tested 2 Java classes without writing any code. You must be thinking why are we wasting our time testing standard core Java classes that everybody knows are working fine. How to write a meaningful acceptance test for a class of our own? So let's take an example of a trivial Address class. Code is included here for reference:</p>
<p><b>Source Code Address.java</b></p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:90%;padding:5px;">
<pre>public class Address {
   public static class Name {
      private String surname = null;
      private String firstname = null;

      public Name() {
      }

      public Name(Name n) {
         this.surname = n.surname;
         this.firstname = n.firstname;
      }

      public static Object parse(String s) {
         Name n = new Name();
         String[] arr = s.split(" ");
         if (arr.length == 2) {
            n.setFirstname(arr[0]);
            n.setSurname(arr[1]);
         }
         return n;
      }

      @Override
      public String toString() {
         return this.firstname + " " + this.surname;
      }

      public String getSurname() {
         return surname;
      }

      public void setSurname(String surname) {
         this.surname = surname;
      }

      public String getFirstname() {
         return firstname;
      }

      public void setFirstname(String firstname) {
         this.firstname = firstname;
      }
   }

   private int streetNo = 0;
   private String street = null;
   private String city = null;
   private int postcode = 0;
   private String state = null;
   private Name name = null;

   public Address() {
      super();
   }

   public Address(Integer streetNo, String street, String city, int postcode,
     String state) {
      super();
      setAddress(streetNo, street, city, postcode, state);
   }

   public void setAddress(Integer streetNo, String street, String city,
     int postcode, String state) {
      this.streetNo = streetNo.intValue();
      this.street = street;
      this.city = city;
      this.postcode = postcode;
      this.state = state;
   }

   public void setStreetNo(Integer streetNo) {
      this.streetNo = streetNo;
   }

   public Integer getStreetNo() {
      return this.streetNo;
   }

   public String getStreet() {
      return this.street;
   }

   public void setCity(String city) {
      this.city = city;
   }

   public String getCity() {
      return this.city;
   }

   public void setPostcode(int postcode) {
      this.postcode = postcode;
   }

   public int getPostcode() {
      return this.postcode;
   }

   public String getFullAddress() {
      return this.streetNo + " " + this.street + ", " + this.city + ", "
        + this.state + " - " + this.postcode;
   }

   public void setStreet(String street) {
      this.street = street;
   }

   public String getState() {
      return this.state;
   }

   public void setState(String state) {
      this.state = state;
   }

   public Name getName() {
      return this.name;
   }

   public void setName(Name name) {
      this.name = name;
   }
}</pre>
</div>
<p>Let's assume I compiled this Address class and added it in FitNesse classpath. Now let's go about writing an acceptance test table for this Address class using Generic Fixture.</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:90%;padding:5px;"><code>!&#124; Generic Fixture &#124; Address &#124; 123 &#124; Nutley Street &#124; New York &#124; 21019 &#124; NY &#124;<br />
&#124; getStreetNo &#124; &#124; 123 &#124;<br />
&#124; getCity &#124; &#124; New York &#124;<br />
&#124; getState &#124; &#124; NY &#124;<br />
&#124; getFullAddress &#124; &#124; 123 Nutley Street, New York, NY - 21019 &#124;<br />
&#124; setStreetNo &#124; 111 &#124;<br />
&#124; setPostcode &#124; 20133 &#124;<br />
&#124; getPostcode &#124; &#124; 20133 &#124;<br />
&#124; getStreetNo &#124; &#124; 111 &#124;<br />
&#124; getState &#124; &#124; NY &#124;<br />
&#124; setName &#124; John Smith &#124;<br />
&#124; getName &#124; &#124; John Smith &#124;<br />
</code></div>
<p>Click on Test button and you will get:</p>
<p><b>Assertions:</b> 8 right, 0 wrong, 0 ignored, 0 exceptions</p>
<p>Pay special attention to setName method in above test table. This method is taking a user defined object of Name type. Since I have implemented public static Object parse(String str) method in above code, generic Fixture is able to construct a Name object from the entered string "John Smith" in the table cell.</p>
<p>For the reference purpose above fixture is executing this Java code using Java reflection APIs:</p>
<div style="border:1px dashed black;background-color:#f9f9f9;text-align:left;font-size:90%;padding:5px;"><code>Address addr = new Address(123, "Nutley Street", "New York", 21019, "NY" );<br />
assertEquals ( addr.getStreetNo(), 123 );<br />
assertEquals ( addr.getCity(), "New York" );<br />
assertEquals ( addr.getState(), "NY" );<br />
assertEquals ( addr.getFullAddress(), "123 Nutley Street, New York, NY - 21019" );<br />
addr.setStreetNo ( 111 );<br />
addr.setPostcode ( 20133 );<br />
assertEquals ( addr.getPostcode (), 20133 );<br />
assertEquals ( addr.getStreetNo(), 111 );<br />
assertEquals ( addr.getState(), "NY" );<br />
addr.setName ( "John Smith" );<br />
assertEquals ( addr.getName(), "John Smith" );</code></div>
<p>That's it, writing acceptance tests could be as simple as that. One more good thing about this Generic Fixture is that it eliminates the need of writing a separate Unit test class (eg: JUnit) for testing your business class.</p>
<p>Generic Fixture <a href="http://anubhava.wordpress.com/2008/02/09/download-and-install-instructions/">download and install instructions</a> can be found <a href="http://anubhava.wordpress.com/2008/02/09/download-and-install-instructions/">on this page</a>. And here is the <a href="/2008/02/09/genericfixturejava/">complete source code</a> for Generic Fixture for browsing. Please leave your comments, suggestions, bug reports, area of improvements and criticism for this effort.</p>
<h3><a href="/2008/02/08/use-of-variables-arrays-and-complex-types-in-generic-fixture/">Next Part: Use of variables, arrays and complex types in Generic Fixture</a></h3>
<p style="font-size:130%;color:#660000;font-family:trebuchet ms;text-decoration:underline;">Coming up: Writing web application tests using this Generic Fixture In the next post I will demonstrate use of this Generic Fixture in writing some useful acceptance tests for Web applications.</p>
<p>Visit <a href="http://tech.groups.yahoo.com/group/fitnesse/message/9723" target="_blank">FitNesse Group Forum</a> for a meaningful and thought provoking discussion on Generic Fixture.</div>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Testing von Webapps mit Selenium]]></title>
<link>http://code4j.wordpress.com/2007/09/10/testing-von-webapps-mit-selenium/</link>
<pubDate>Mon, 10 Sep 2007 19:54:59 +0000</pubDate>
<dc:creator>xandrox</dc:creator>
<guid>http://code4j.wordpress.com/2007/09/10/testing-von-webapps-mit-selenium/</guid>
<description><![CDATA[Am Wochenende bin ich zufällig auf das Selenium IDE Firefox Addon gestoßen. Ich hatte bereits in d]]></description>
<content:encoded><![CDATA[<p>Am Wochenende bin ich zufällig auf das <a href="https://addons.mozilla.org/de/firefox/addon/2079">Selenium IDE Firefox Addon</a> gestoßen. Ich hatte bereits in der Vergangenheit von <a href="http://www.openqa.org/selenium/">Selenium</a> und seiner unkonventionellen Funktionsweise gehört, doch nun musste es Testen. Ich gebe zu: das Firefox klicki bunti Plugin mach an :-).<br />
<!--more--><br />
<strong>Bild der Selenium IDE:</strong><br />
<img src="http://www.openqa.org/selenium-ide/selenium-ide.gif"></p>
<p>Selenium ist ein Acceptance Testing Framework für Webanwendungen. Die Revolutionäre Idee daran ist das nicht wie bei den Üblichen Test-Frameworks ein Proxy zwischen Client und Server geschalten wird, der dann nur stur die Aufgenommenen Requests abspult, sondern der Browser selbst spielt den Test ab.</p>
<p>Der Vorteil liegt auf der Hand: Erstmals ist es möglich die Anwendung einschließlich Client vollständig zu testen. Javascripts / AJAX und jegliches Client Verhalten lässt sich mit testen. Einfach genial. Ich persönlich hätte nie geglaubt das man irgendwann vernünftige Webclient-Tests mit erträglichen Aufwenden realisieren kann.</p>
<p>Und das beste ist es funktioniert erstaunlich gut. In wenigen Minuten hatte ich mein erstes Testcase mittels der Selenium IDE erstellt. Prüfungen lassen sich intuitiv per Markierung und dem Command "verifyTextPresent" dem Test hinzufügen.</p>
<p>Was für mich nach dem ganzen geklicke noch wichtig war ist die Test Automatisierung. Hierfür gibts Selenium RC (Remote Control), eine Art Server der die aufgezeichneten Tests in einem Browser automatisiert abspielen lässt. Fernbedient wird das ganze dann wahlweise durch die JUnit Tests die durch Senenium IDE generiert wurden. Ach hier muss man sagen es funktioniert wenngleich die Release Version 0.9.0 nicht zu den JUnit Tests passte. Mit 0.9.1-SNAPSHOT hat dann jedoch alles funktioniert.</p>
<p>Ein bisschen Ärger hatte ich noch mit SSL und Selenium RC aber die getestete Anwendung war auch kein "Hello World" Beispiel. Mit SSL basierten Webanwendungen die Ihre Ressourcen von einem Server beziehen sollte es kein Problem geben.</p>
<p>Somit bleibt mir nur zu sagen: <strong>Check it Out!</strong></p>
<p>Sobald ich die ersten Projekterfahrungen habe werde ich wieder Berichten.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Download and Install Instructions]]></title>
<link>http://anubhava.wordpress.com/2008/02/20/download-and-install-instructions/</link>
<pubDate>Sun, 10 Feb 2008 01:50:16 +0000</pubDate>
<dc:creator>anubhava</dc:creator>
<guid>http://anubhava.wordpress.com/2008/02/20/download-and-install-instructions/</guid>
<description><![CDATA[Install Requirements
You must have FitNesse framework installed on your computer and FitNesse server]]></description>
<content:encoded><![CDATA[<h2>Install Requirements</h2>
<p>You must have <a href="http://fitnesse.org/" target="_blank">FitNesse framework</a> installed on your computer and FitNesse server must be running on the computer where Generic Fixture is being installed.</p>
<h2>To download Generic Fixture</h2>
<p>Download the jar file genericfixture.jar containing full source code and compiled classes from <a href="http://sourceforge.net/projects/genericfixture" class="wiki_link_ext" rel="nofollow">Generic Fixture Sourceforge Site</a>. Included classes have been generated using Sun's JDK 1.5 Java compiler. Should you need to build Generic Fixture with any other JVM then make sure to put fitnesse.jar and fitlibrary.jar (provided in all the Fitnesse releases) in your CLASSPATH.</p>
<h2>To install Generic Fixture</h2>
<p>Save genericfixture.jar somewhere on your computer where FitNesse server is running. Then simply add genericfixture.jar in your classpath on FitNesse Wiki. eg:</p>
<p>!path /path/to/download/dir/genericfixture.jar</p>
<h2>Examples and Tutorial</h2>
<p>Please visit <a href="http://genericfixture.wiki.sourceforge.net/Introducing+Geneic+Fixture+for+FitNesse" rel="nofollow">http://genericfixture.wiki.sourceforge.net/Introducing+Geneic+Fixture+for+FitNesse</a></p>
]]></content:encoded>
</item>

</channel>
</rss>
