Translate

Showing posts with label Acceptance testing. Show all posts
Showing posts with label Acceptance testing. Show all posts

Saturday, 13 July 2013

DBFit + Slim + LocalDB

Cool!

Only word to  describe the way you can work with databases nowadays.

As I tried to figure out a way to work with a complex set of data using stored procedures (add to to this a SQL Server error that disallowed attaching a database file to the server), I realized the incredible number of options available to work with the database file - 1. Azure storage  2. Visual Studio  Data Connection  3. LocalDB  4. Read data in XML and import from XML file into DB and the list could go on, if one applies one's mind to it! Although I have not tried this but it may even be possible to use Excel to work with the DB (with the DataConnection or is it UDL or F?)...

So, first I tried to connect with VS to the LocalDB and succeeded in attaching the .mdf file.

Next, I wanted to test the stored procedures in the DB and since writing code to execute the procs looked tedious, decided to use the Management Studio 2012 to connect to the LocalDB and succeeded without any error!

So, executing the stored procedures is a simple step but I was not satisfied and so decided to use DBFit and since I wanted to write some functional acceptance tests, my first thought went to Slim!

A fantastic tool, Slim, just got better with support (this word 'support' is contentious as the DBFit team (or was it the Slim team)?) :D insists that there is no Slim support for DBFit) for  DBFit!

All you need to do is download DBFit and extract it into the Fitnesse folder and run the StartFitnesse.bat file (in Windows).

One of the more likely problem areas will be the connection string to the database from DBFit. If  you are a VS user for long, you will manage but if  you are not here is one connection string that you would like to use

Below is the LocalDB connection string, for integrated security, that you may not find anywhere else -

!|connect|Data Source=(LocalDB)\v11.0;AttachDbFilename='path to database file';Integrated Security=True;Connect Timeout=30|

The simpler one is

!|Connect|JV-PC|YourUserName|YourPassword|YourDatabaseName|

You can use almost any command you may otherwise use in the database environment and so the script to test 'Transaction' is

!|DatabaseEnvironment|
|commit|

!|DatabaseEnvironment|
|rollback|

Use the Rollback script in the TearDown fixture as is so that it could use the default, or the current connection/transaction.

Super cool!

Connect to http://localhost:8085/ after starting the Fit server with StartFitnesse.bat

Create a page by typing it in the address bar and type or copy/paste the below code, Save, Change the
properties of the page to Test, save the properties and theTest menu item will appear.

A simple query syntax to start with DBFit and Slim

!define COMMAND_PATTERN {%m -r fitnesse.fitserver.FitServer,"FitSharp\fit.dll" %p}
!define TEST_RUNNER {FitSharp\Runner.exe}
!define PATH_SEPARATOR {;}
!path FitSharp\dbfit.sqlserver.dll

!|dbfit.SqlServerTest|

|Query|SELECT n FROM ( SELECT 1 as n union all select 2 union all select 1 ) x |
|n|
|2|
|1|
|3|

|Ordered Query|SELECT n FROM ( SELECT 1 as n union select 2 union select 3 ) x|
|n|
|1|
|2|
|3|


You can also execute stored procedures, functions and any query that you may otherwise be executing with SSMS.


Tuesday, 11 June 2013

Slim help (no pun intended!) !

Before I begin this post, let me say this -

Do not forget to leave a "Thank you" comment if this helped you in using Slim. I know the worth of this post as there is hardly any online help (simple ones that is) on Slim!

Even though I started using Slim 3-4 years back, I still find it can behave unpredictably, unlike other tools so I am posting some tips here. :P

Tip #1 - Use the Format button on the Wiki but wait! It may format your wiki code but it is not a magic wand and you must use it as an informed user. For instance, if you write a wiki line of code like "'{some line here |' the "{" will not be declared as an error!! So, the Format button only helps experienced Slim/FitNesse coders.

Tip #2 - There is no logic to this tool. It is as open for "trial and error" as you could imagine, so go ahead and try all the syntax that you know!

Well, okay, jokes apart, here is the real one!

To start using Slim, you will need the Fitnesse.jar file and Slim Download Fitnesse and Slim. Extract it after downloading and navigate to your Fitnesse folder (through command prompt) and type
"java - jar fitnesse.jar " (or the name of the .jar file as may be). This will launch your fit server on port "80". If  the port is not available, type "java -jar fitnesse.jar -p 9888 (or any other number)".

In your favorite browser, type localhost (this example is based on Windows 7 Home Basic (no IIS default)): and you will be at home with Fitnesse ! :)

Create a new page "HelloWorld" by typing it in the address bar of the browser and an editable text box will open.

Delete the !contents line. In the empty text box, enter the following lines -

!define TEST_SYSTEM {slim}
!define TEST_RUNNER {e:\fitSharp\Runner.exe}

!define COMMAND_PATTERN {%m -r fitSharp.Slim.Service.Runner,e:\fitSharp\fitSharp.dll %p}

!path DllDrive:\yourDLLpath\YourDllLibrary.dll

Explanation
The first line indicates that you want to use Slim - default is "fit". The second line says use Slim Runner to execute the tests in your page. The third line is the service that is to be used by Slim and the location of the Slim library. The 4th line is the path where your C# domain library resides! That is it! 

The "!" mark is used wherever you want to let Fitnesse know that the following lines should not be used as a wiki code and formatted!

There are various techniques for writing Acceptance tests and it is beyond the scope of this post so I will introduce the tools used in Slim - tables.

There are Decision, Scenario, Table, Script, query, import....tables. Each has its own applicability and to learn about them you can take a look here.

Scenario table

Scenario tables are my favorite in Slim because of my inclination towards BDD (Behavior Driven Development). 

A scenario table, as the name indicates, describes scenarios (use cases/user stories) and by itself does not do anything so if you wish to impress somebody in your team/management, you can simply declare a scenario like this and it will show "Green"!

|Scenario||myScenario|

|myScenario|

Below is an example screen(s) of a scenario table with the Slim script following it and the C# code after it.

The script of the last scenario in the script has not been included and you can use that as an exercise !

Similarly, the class name and the namespace names have been left out in the C# screenshot that you can use as an exercise!