Testing D database calls code for regression

Ali fakeemail at example.com
Mon Mar 19 22:46:12 UTC 2018


On Friday, 16 March 2018 at 20:17:49 UTC, aberba wrote:
> How will you test D code which makes calls to database to 
> detect bugs and regression. Unlike where you can inject data 
> like assert (2+1 == 3), database interfacing code will be 
> crazy... Or there's some mocking available for such cases. 
> Especially when more features are developed on top.

Well, I am not really sure what you are looking for
but to test database code, there are frameworks for this

Check for example tsqlt ( http://tsqlt.org/ )
this framework is ms sql specific and is the one I have 
experience with

There is also dbfit ( http://dbfit.github.io/dbfit/ ) which seem 
to support more database management frameworks

tsqlt is very good for unit testing, sql procedures or statements
at a high this is how it was setup to be used

1. you prepare sql procedure to create your tables that will be 
used in testing
2. you prepare sql procedure with insert statements to create the 
data sample you want to be used for testing
3. you write a script execute the two procedures from the first 
two step then executed the procedure or statement  you want to 
test and then at the end of this script executed some assert 
statements that is basically your unit test

how to setup used those scripts
1. the setup started a transaction
2. the setup dropped everything in the database
3. the setup executed the scripts from point 3 above to create 
your database, followed by the insert statements scripts or data 
creation script, followed by executing the statement to be tested 
and finally executing the assert statements
4. finally the setup rolled back everything

this setup was support by the tsqlt framework, but honestly i 
dont know how much of this was specific to the environment where 
i worked

but you can use tsqlt to have this

D is not a database language, D is not sql
You should clearly separate testing the D code that call the sql 
statements and testing the sql statements themselves

The above frameworks, will help you test the sql code in isolation



More information about the Digitalmars-d-learn mailing list