Order Entry – Integration testing

An integration test may use the database, The point of this exercise, therefore, is to provide scripts that allow us to backup and restore the database, so that every time our tests run, we start with the database in the same state.

Converting from embedded database to SQL

In order to enable the SQL Driver, it is necessary to run DataFlex Studio as administrator.

From the Database menu, select “Configure Database Drivers”, select MSSQL, check “Load on startup”, and select “Load now”.

Then, we select Configure Database Connection from the Database menu in Dataflex Studio. We use “Create Database”, and finish the connection.

From the Database Builder, we select “Convert to MS SQL Server”, select all tables, and click through the wizard using all the defaults. Now we have an SQL database ready to use.

Creating a database restore script

We want to be able to run integration tests repeatedly, with the same data every time. To accomplish this, we first make a backup file. From SQL Server Management Studio, right click on the database, select Tasks and Back Up. We set the Destination to a file inside our Project folder. We might even check it into source control.

If you want to automate this task, you can select the option “Script Action to File” from the Script pulldown menu. This will create a .SQL script file that you can run later. You can run the file, and it will execute the script through SQL Server Management Studio, or you can create a custom batch file where you specify details about which SQL server instance to use:

sqlcmd -S myServer\instanceName -i “C:\Projects\Automated Testing\Order Entry\backup_database.sql”

Finally, we do the reverse, to create the script to restore the database. This is the step which enables us to run the integration tests with the same data every time.

In SQL Server Management Studio, right click on the database, select Tasks, and Restore Database. The Source is our backup file (Device). In Options, we select “Overwrite the existing database (WITH REPLACE)”, and “Close existing connections to existing database”. Finally, we select “File” from the Script pulldown menu, to create the restore script file. Then, at last, we create a batch file to run the restore script:

sqlcmd -S myServer\instanceName -i “C:\Projects\Automated Testing\Order Entry\restore_database.sql”

Commiting our changes to source control

We have converted our workspace to MS SQL, and added a backup file and some scripts. We select all those changes in TortoiseHg, and commit them.

commit database changes

And voila, we are now ready to write integration tests that start with a fresh database every time.


Adding VDFUnit as a subrepo for your project

We want to add VdfUnit as a library, by adding it as a Mercurial subrepository. We solve this by adding both the Order Entry and the VdfUnit repositories as subrepos under a new “super” repo. Selecting the parent folder (Automated Testing), we right click, select TortoiseHg, and Create Repository Here.

Inside this folder, right click again, and select TortoiseHg and Clone. In Source, we paste the BitBucket URL: “https://bitbucket.org/olaeld/vdfunit”. Then we press the “Clone” button. This will clone the repo from BitBucket.

Now, we need to tell the Automated Testing repo that it has to use two subrepos. We create a file named .hgsub, and add two lines

Order Entry = Order Entry
vdfunit = vdfunit

Opening the Commit view in TortoiseHg, and refreshing it, allows us to “Add” .hgsub. This will bring up our two subrepos, and we can commit the changes.

Add subrepo

In DataFlex Studio, we can select Maintain Libraries from the Tools menu, and select the appropriate VDFUnit workspace.

You’re now ready to select File -> New Project -> VDFUnit TestRunner Project, and start writing unit tests!

file new project

Unit Testing the #DataFlex Order Entry Project Part 1 – Setting up Version Control

I start by making a copy of the project from C:\ DataFlex 18.2 Examples to the folder C:\Projects\Automated Testing.

Making a version control repository

I am using Mercurial, with GUI front-end tool TortoiseHg, but you can do the same in Git. (There are of course many version control systems available, but I wholeheartedly recommend using a distributed version control system, such as Mercurial or Git.)

The first thing I do is create a Mercurial repository. In Windows Explorer, right click on the folder “Order Entry”, select TortoiseHg, and “Create Repository Here”

Creating a repository

I keep the default settings, and select Create.

New Repository dialog

Before checking in the workspace, I tell Mercurial to ignore certain files that are created automatically. A good starting point is Dennis Piccioni’s blog entry, Configuring Source Control for Visual DataFlex. I end up with the following .hgignore file:

syntax: glob


















Finally, I check in all the files. First, I select the Commit view in TortoiseHg.

Commit view.PNG

Then, I select all the files, press the Commit button, and enter a commit message (confirming to add the selected untracked files).


Finally, I start DataFlex Studio, compile and run the Order Entry project, and check to see if any files have changed.

In TortoiseHg, in the Commit view, I press F5 (refresh), and see that two files have indeed changed:

changed files.PNG

Upon closer investigation, the Order.cfg file has AutoIncrementBuild=1. So this file will change every time I compile the project. Since these files don’t contain any information that I am interested in for this particular project, I right-click on the files and add them to .hgignore.

Now we have our project under version control, and can move with greater freedom – because we can always go back if we mess something up.

The final step is to add the VDFUnit library as a subrepository for the project.