Wrapping my mind around Slim Query Tables

Posted on September 18, 2009. Filed under: test automation |

I started using the Slim test framework (the .NET implementation) about two weeks ago, but had worked primarily with scenario, script , and decision tables up until yesterday. (Scenario tables ROCK btw and I will blog about them soon).

Yesterday I started working on an automated test (or, if you prefer, collection of checks) that needed to verify data in a result set, so I started learning about the Slim Query table. The query table example and corresponding fixture code presented in the FitNesse user guide are fairly straightforward. The part that I really had to wrap my head around was the statement “The fixture class must have a query method that returns a list of rows. Each row is a list of fields. Each field is a two-element list composed of the field name and its string value.” Say whaaat?

Now, maybe for those of you who have more of a programming background than I do, you might have read that statement and immediately pictured what the Query results “look” like. I didn’t. I’m used to thinking of query results as a table, not as lists of lists. I had to create a visual.

Given this result set:

SampleTable

Starting at the lowest level, we have “Each field is a two-element list comprised of the field name and its string value.” OK, so for row 0 column 0 we’d have:

row0Col0

For row 0 column 1 we’d have:

row0Col1

etc.

Let’s go up a level. “Each row is a list of fields.” That makes sense now. For row 0 we’d have:

row0List

Finally, the Query method “returns a list of rows.” Ohhh now it makes sense.

listOfRowsOfColValPairs

Hmm…but then I had to figure out how to translate a DataTable result set into the list of this format. It was actually pretty simple; iterate through the rows and columns to create what I call column-value pairs, collect each row’s column-value pairs into a list, then collect the rows into a list.

I’ve provided my solution below (sorry about the formatting – this theme’s code tag sucks).

It’s a method that takes a DataTable and creates the list of lists of column-value pairs that will work with Slim Query tables. So, in each Slim Query Fixture class, I just call off to the method and pass in the DataTable of results, then return the list of lists of column-value pairs from the Query() method.


using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace Your.Namespace.Here
{
public static class SlimQueryResultsHelper
{
// Convert a result set in DataTable format to the format required by the Slim Query test table
public static List ConvertDataTableToObjectList(DataTable theTable)
{
List queryResults = new List();
foreach (DataRow row in theTable.Rows)
{
List rowListOfColumnValuePairs = new List();
foreach (DataColumn col in theTable.Columns)
{
List columnValuePair = new List();
object val = row[col];
columnValuePair.Add(col.ColumnName);
columnValuePair.Add(val == DBNull.Value ? "null" : val);
rowListOfColumnValuePairs.Add(columnValuePair);
}
queryResults.Add(rowListOfColumnValuePairs);
}
return queryResults;
}
}
}

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

3 Responses to “Wrapping my mind around Slim Query Tables”

RSS Feed for The Testing Blog Comments RSS Feed

[...] Wrapping my mind around Slim Query Tables « The Testing Blog thetestingblog.com/2009/09/18/slim-query-tables – view page – cached I started using the Slim test framework (the .NET implementation) about two weeks ago, but had worked primarily with scenario, script , and decision tables up until yesterday. (Scenario tables ROCK btw and I will blog about them soon). — From the page [...]

i have no idea what you are talking about, but i’ll keep checking back just in case there is something i might understand sometime.:)

Well, I was going to remark that I would have returned a list of lists of dictionaries (List<List<Dictionary>>), but then I re-read and saw that it was asking for a list of lists of lists of strings (List<List<List>>).

So, tweeking the code you have above:

using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace Hire.Steverb
{
public static class SlimQueryResultsHelper
{
// Convert a result set in DataTable format to the format required by the Slim Query test table
public static List<List<List>> ConvertDataTableToObjectList(DataTable theTable)
{
List<List<List>> queryResults = new List<List<List>>();
foreach (DataRow row in theTable.Rows)
{
List<List> rowListOfColumnValuePairs = new List<List>();
foreach (DataColumn col in theTable.Columns)
{
List columnValuePair = new List();
object val = row[col];
columnValuePair.Add(col.ColumnName);
columnValuePair.Add(val == DBNull.Value ? "null" : val.ToString());
rowListOfColumnValuePairs.Add(columnValuePair);
}
queryResults.Add(rowListOfColumnValuePairs);
}
return queryResults;
}
}
}


Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...

Follow

Get every new post delivered to your Inbox.