Using DBFit for test data preperation

1,077 views
Skip to first unread message

Christian Baumann

unread,
Jun 27, 2011, 10:19:18 AM6/27/11
to dbfit
Hi all,

I want to use DBFit as preperation for my integration tests:
- In the setup I want to inject test data into the DB.
- Use that data during the test execution
- In the deardown I want to delete the data again, which I injected
during the setup

I´ve got it running with DBFit in Flowmode mode, as long as I´m only
using DBFit. As soon as I´m using my own fixture (which inherits from
the DoFixture) I get into trouble. It seems, that for some reason I can
´t access the data in the DB that has been created by the DBFit during
the Setup, so I guess some (transaction)-locking is active here?
I´m using the dotNet Runner & MS SQL Server 2008.

Here is a (simplified) example of what I´m doing:

!define COMMAND_PATTERN {%m -r
fitnesse.fitserver.FitServer,dotnet2\fit.dll %p}
!define TEST_RUNNER {dotnet2\Runner.exe }
!path dotnet2\*.dll
!path C:\path\to\my_fixture.dll

!|dbfit.SqlServerTest|

!|Connect|sql_connection_string|

|Execute|INSERT INTO Table (col1, col2) VALUES ('val1','val2')|

|Query |SELECT * FROM Table|
|col1? |col2? |ObjCode? |
|>>var0|>>var1|>>var2 |

!|Some.Namespace.My_fixture |
|Intialize |
|A test step |
|Set value of|something|to << var0|
|Another test step |
|Verify |

In this case, in var0 the ID of the inserted dataset is stored.
It fails at "another test step" and the exception thrown by my code is
exactly the same, as if the dataset would not exist in the DB.

Any advices or hints?

Thx in advance,
Christian

Christian Baumann

unread,
Jun 28, 2011, 8:09:30 AM6/28/11
to Gojko Adzic, db...@googlegroups.com
Thanks Gojko, for the advice.

I´ve decided to go for the standalone mode and modified my test as follows:

!|Import      |
|dbfit.fixture|

!|DatabaseEnvironment|SqlServer                                                                                                                            |

|Connect             |sql_connection_string|

|Execute|INSERT INTO Table (col1, col2) VALUES ('val1','val2')|

|Query |SELECT * FROM Table|
|col1? |col2?   |ObjCode?  |
|>>var0|>>var1|>>var2       |

!|DatabaseEnvironment|
|commit              |


!|Some.Namespace.My_fixture       |
|Intialize                        |
|A test step                      |
|Set value of|something|to << var0|
|Another test step                |
|Verify                           |

!|DatabaseEnvironment|
|rollback              |

It´s working fine, except for the rollback. None of the executed stuff on the db is being rolled back. :-(
Any advice?

Thx,
Chrisitan

2011/6/27 Gojko Adzic <goj...@gmail.com>
Hi Christian,

DbFit (intentionally) uses transaction in flow mode and rolls back a
transaction at the end if you don't commit. This is to make tests
repeatable and runnable in parallel. You have two options: commit from
the test and clean up yourself ( just put |commit| in a single line
before your fixture) or use dbfit in standalone mode, where you define
the transaction scope and can pass on the tx scope to your fixtures as
well.

gojko

Gojko Adzic

unread,
Jun 28, 2011, 8:15:41 AM6/28/11
to dbfit
once you commit, that issues a DB commit so you can't roll that back.
in your fixture, grab the current tx context from the
databaseenvironment fixture and use it to execute your db commands,
then roll back everything at the end without committing.

gojko

Christian Baumann

unread,
Jun 29, 2011, 3:51:46 AM6/29/11
to db...@googlegroups.com
Thanks again!

Just for the records (since I´m a .net-newbie and could not find detailled info about this in the web):
- Add dbfit DLLs to the references of the .net project
- transaction is available in dbfit.DbEnvironmentFactory.
DefaultEnvironment.CurrentTransaction

Regards,
Christian


2011/6/28 Gojko Adzic <goj...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "dbfit" group.
To post to this group, send email to db...@googlegroups.com.
To unsubscribe from this group, send email to dbfit+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dbfit?hl=en.


MatMan

unread,
Feb 15, 2013, 5:39:02 AM2/15/13
to db...@googlegroups.com, chri...@gmail.com
What are the varibles fitnesse_path and fitnesse_path_db_fit set to? Do those directories include the dbfit JAR files?
 

On Friday, 15 February 2013 07:26:45 UTC, roy...@gmail.com wrote:
Hi all,
      I'm trying to connect to the SQLServer 2005 but getting an error;
Error:could not find fixture:Connect
 
My code:

!5 TC: TestCase_DC01

 

!5 Initialization

!path ${fitnesse_path}

!path ${fitnesse_path_db_fit}

 

!|import fixture|

|dbfit.fixture|

 

!5 Connect to Database

!|DatabaseEnvironment|SQLSERVER|

!|Connect|localhost|aqroy|Aimhealth4|AIMDBQA02|

 

!5 Validate for AppName as ClaimForm in dbo.AppMst table

 

!|Query|Select AppName from AIMEE.dbo.AppMst where AppMstGUID = 'BF40E368-414A-40E4-B49F-6DCA71635D4D'|

|ClaimForm|

|AppName|

could anyone help me on the same?.

 

Thanks,

Antony

MatMan

unread,
Feb 15, 2013, 5:39:53 AM2/15/13
to db...@googlegroups.com, chri...@gmail.com
Sorry, was assuming dbfit/Java,.....or the dbfit.dll file.

On Friday, 15 February 2013 07:26:45 UTC, roy...@gmail.com wrote:
Hi all,
      I'm trying to connect to the SQLServer 2005 but getting an error;
Error:could not find fixture:Connect
 
My code:

!5 TC: TestCase_DC01

 

!5 Initialization

!path ${fitnesse_path}

!path ${fitnesse_path_db_fit}

 

!|import fixture|

|dbfit.fixture|

 

!5 Connect to Database

!|DatabaseEnvironment|SQLSERVER|

!|Connect|localhost|aqroy|Aimhealth4|AIMDBQA02|

 

!5 Validate for AppName as ClaimForm in dbo.AppMst table

 

!|Query|Select AppName from AIMEE.dbo.AppMst where AppMstGUID = 'BF40E368-414A-40E4-B49F-6DCA71635D4D'|

|ClaimForm|

|AppName|

could anyone help me on the same?.

 

Thanks,

Antony

 

On Monday, June 27, 2011 7:49:18 PM UTC+5:30, Christian Baumann wrote:

Jake Benilov

unread,
Feb 16, 2013, 2:07:47 PM2/16/13
to db...@googlegroups.com
Hi Antony,

I was not able to reproduce the error that you are seeing. Could you please provide a bit more information about your set-up, such as:
1) which distribution of DbFit you are using (e.g. the one from Sourceforge, or perhaps the fitsharp distribution?)
2) which version of Fitnesse you are using?
3) are you running under windows or another operating system?
4) The definitions of fitnesse_path and fitnesse_path_db_fit? Does the latter glob the dlls/jars?

regards,
Jake


On Friday, 15 February 2013 07:26:45 UTC, roy...@gmail.com wrote:
Hi all,
      I'm trying to connect to the SQLServer 2005 but getting an error;
Error:could not find fixture:Connect
 
My code:

!5 TC: TestCase_DC01

 

!5 Initialization

!path ${fitnesse_path}

!path ${fitnesse_path_db_fit}

 

!|import fixture|

|dbfit.fixture|

 

!5 Connect to Database

!|DatabaseEnvironment|SQLSERVER|

!|Connect|localhost|aqroy|Aimhealth4|AIMDBQA02|

 

!5 Validate for AppName as ClaimForm in dbo.AppMst table

 

!|Query|Select AppName from AIMEE.dbo.AppMst where AppMstGUID = 'BF40E368-414A-40E4-B49F-6DCA71635D4D'|

|ClaimForm|

|AppName|

could anyone help me on the same?.

 

Thanks,

Antony

 

On Monday, June 27, 2011 7:49:18 PM UTC+5:30, Christian Baumann wrote:

Jake Benilov

unread,
Feb 16, 2013, 2:17:30 PM2/16/13
to db...@googlegroups.com
Another thought: are you seeing any errors in the error logs of the test execution? If there were any, you can see them by clicking on the "Errors occurred" link, or visit http://host:port/ErrorLogs.<Your.Test.Path> URL... (if there were no errors then you should see "Test executed OK")


On Friday, 15 February 2013 07:26:45 UTC, roy...@gmail.com wrote:
Hi all,
      I'm trying to connect to the SQLServer 2005 but getting an error;
Error:could not find fixture:Connect
 
My code:

!5 TC: TestCase_DC01

 

!5 Initialization

!path ${fitnesse_path}

!path ${fitnesse_path_db_fit}

 

!|import fixture|

|dbfit.fixture|

 

!5 Connect to Database

!|DatabaseEnvironment|SQLSERVER|

!|Connect|localhost|aqroy|Aimhealth4|AIMDBQA02|

 

!5 Validate for AppName as ClaimForm in dbo.AppMst table

 

!|Query|Select AppName from AIMEE.dbo.AppMst where AppMstGUID = 'BF40E368-414A-40E4-B49F-6DCA71635D4D'|

|ClaimForm|

|AppName|

could anyone help me on the same?.

 

Thanks,

Antony

 

On Monday, June 27, 2011 7:49:18 PM UTC+5:30, Christian Baumann wrote:
Reply all
Reply to author
Forward
0 new messages