Blog

DBFit and SQL Server: How to connect and create your first test

Free copy of SQL Best Practices?

Get your copy of SQL Best Practices and be the database developer that has rocket fuel in his veins.
Even better? These Best Practices are written in an easy to understand format so your whole team will quickly want to adopt them.
Get SQL Best Practices

I love the idea of DBFit (being able to run tests against every database system under the sun) but have found it very challenging to get up and running. There is documentation but it seems to assume a level of familiarity with FitNesse that I definitely did not have. The primary hurdle for me was getting the SQL Server JDBC drivers set up for DBFit and then creating the connection string in the right format.

Using the steps below you will be able to connect to a specific SQL Server database on a named instance using integrated security. The code below will then run a quick test, returning the word "test" in a column called "x".

The first step is of course download the latest version of DBFit from GitHub, install it and get it running locally. The first step of the DBFit Getting Started was no prob and spot on.

Unzip the dbfit zip somewhere on your disk, and then run startFitnesse.bat (just double-click it). A command window will open similar to this:

DBFit Command Window

The next step is to create a very simple test to ensure we can connect to our SQL Server and run a quick query.

Enter the following URL into your web browser:

http://localhost:8085/SqlServerTest

This will bring up a blank page (DBFit/FitNesse are based on wiki style logic where if there is a reference to a page that doesn't exist it is assumed you will create it). The blank page looks like this:

DBFitFirstTestBlankTest

Cut and past the following code into the window on the page, customizing it to match the server and database name in your environment.

!path lib/*.jar
!|dbfit.SqlServerTest|
!|Connect|jdbc:sqlserver://theservername\theinstancename;integratedSecurity=true;databaseName=thedatabasename|
!|Query| select 'test' as x|
|x|
|test|

Make sure to choose TestPage from the drop down and click the save button at the bottom of the page (see green arrows below).

DBFit Setup First Test

If you followed the directions closely the next screen you'll see will look like the screen shot below and include a "Test" button on the top menu.

DBFitReadyForFirstTest

 

Click the "Test" button and you should get a green light verifying you successfully connected to your SQL Server and executed a query!

SuccesfulDBFitSQLServerTest

If you didn't get the green light work back through the steps above and ensure you didn't miss any steps. If you ran into any issues feel free and post the error in the comments and hopefully myself or another member of the community will be able to help!

Tags: , ,

No comments yet.

Leave a Reply