Running your first tests

Last modified: 2011-02-28

This blog is the second in a two part series.

It will look at:

  • running the some simple tests against the database
  • using the provided SQL helper scripts to help get the properties for an existing database.

It assumes that you have read the first blog in the series – initial set up and configuration.

Example test to be run

The DBTestUnit download comes with a number of sample test files including:


(Note ‘DIR’ is used as a token for ‘C:\Projects\AdventureWorks\’ – the example project set up in initial set up and configuration).

This allows tests to be run against the SQL server that hosts the database – to ensure it has the expected properties.

An example is shown below:

using System;
using MbUnit.Framework;
using DBTestUnit.UnitTestBaseClass.MSSQL;
using DBTest = DBTestUnit.InfoSchema;

namespace DBTemplate.DatabaseTest.Tests
    public class SQLServer : SQLServerTestBase
        public SQLServer()
            dbInstance = "AdventureWorks";
            sqlServer = new  DBTest.SQLServer(dbInstance);
            expectedServerCollation = "Latin1_General_CI_AS";
            expectedServerVersion = "10.50.1600.1";
            expectedServerProductLevel = "RTM";
            expectedServerEdition = "Developer Edition";

A number of things are worth noting:

  • This is for MS SQL server. The test inherits from SQLServerTestBase part of the DBTestUnit.UnitTestBaseClass.MSSQL namespace. This would need to be changed if testing Oracle or MySQL.
  • The expected values eg expectedServerVersion – will need to be changed appropriately.

This will be used as an example as it is a relatively straight forward set of tests.

How to run the tests
So assuming that everything has been set up and configured correctly how do we run the tests?

1. Open up the VS solution.

If you haven’t already done so open the solution and build/compile the database test project.

The output of this will be a test dll – for example:


2. Open the MBUnit UI

If you need to install either get the latest version from the MBUnit web site or install if from the DBTestUnit download


In the UI go to the menu ‘Assemblies’ – ‘Add assemblies’

Navigate to and attach the db test dll created in step 1.

Run the SQLServer tests.

If the expected properties in the tests are correct then the tests will pass.

3. What do you do if some of the test fail
This will mean that the SQL server that hosts the AdventureWorks – does not have the properties outlined in test code above.

Therefore the sample test code provided needs to be updated with the correct SQL server properties.

(Note this blog is using the scenario where you are starting to carry out database testing for an existing/legacy database.)

The DBTestUnit download provides a number of SQL helper files that will provide information for an existing database.

These can be found in:


4. Using the SQL helper scripts

The script 001_SQLServerSettings.sql is used in this case.

A part of the script is shown below:

PRINT '********************************'
PRINT '********************************'
PRINT 'ProductVersion: ' + convert(varchar,SERVERPROPERTY ('ProductVersion'))
PRINT 'ProductLevel: ' + convert(varchar,SERVERPROPERTY ('ProductLevel'))
PRINT 'Edition: ' + convert(varchar,SERVERPROPERTY ('Edition'))
PRINT 'ServerCollation: ' + convert(varchar,SERVERPROPERTY ('Collation'))

The values returned when this script is run can be placed in the C# test shown above.

It can then be recompiled and the tests run again in MBUnit.

If the values are correct the tests will all pass.

Round up
And that’s it.

The first blog showed how to configure/set up DBTestUnit, this blog has taking this on and shown how to run some initial tests.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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

%d bloggers like this: