How much is it worth paying for tools and services?

We are considering paying for a tool/service. Is it worth the investment? What is involved in deciding this?

Bean counting

Break-even from a “pointy-haired boss”, micro-management, perspective.
$10 per month ≈ 1 minute per day of my time.

Motivation-hygiene factors

Motivation: My work is important to the company. It is in the interest of the business to provide good tools so I can get my work done. This makes me feel valued.

Work conditions: Being forced to use sub-standard tools is equivalent to working in an office that is in poor condition. It is not being cleaned. The chair is uncomfortable. The air is stifling. It is either too cold or too hot. There is a lot of noise, and I am constantly getting interrupted from working on the task at hand.

Conclusion

Just let me do my job, okay?

Disclaimer

I am not not at all disgruntled in my current situation (actually, I am super motivated and happy about my working conditions), but sometimes you just have to say your piece 🙂

Getting DFUnit

DFUnit lives in GitHub. Get it from https://github.com/olaeld/DFUnit

The best way is to use Git. This makes it easier to get updates and to contribute changes.

Here is how you can get DFUnit with TortoiseGit.

First, copy the DFUnit GitHub link: https://github.com/olaeld/DFUnit

Then, in Windows Explorer, browse to a suitable location for your project, right click, and select the TortoiseGit action “Git Clone”.

Git clone DFUnit

Make sure the “Recursive” option is selected, so the DataFlexPatterns submodule (and its submodule, vwin32fh) is cloned.

Running DFUnit

Open the DFUnit example workspace in DataFlex Studio. From the Workspace Explorer, select the DFUnit TestRunner project. Hit F5 to run.

All the tests green?

It’s time to write some tests!

Tip: Reducing compile time

Precompiling packages can help to reduce compile times. Open “DFUnit Precompile.pkg” and select Project -> Precompile -> Precompile package

 

Setting up FitNesse for DataFlex

Download FitNesseForDataFlex

My recommendation is to use Git or Mercurial and clone the repo from https://bitbucket.org/olaeld/fitnessefordataflex

This will ensure that you also get the required subrepo, DataFlexPatterns.

For Mercurial, this is how to do it: First install TortoiseHg, then go to C:\Projects. Right-click, select TortoiseHg, and Clone… In Source, you enter https://bitbucket.org/olaeld/fitnessefordataflex and select “Clone”.

The alternative is to select Download Repository from the Downloads section of these repos. (You will need to manually download both repos, unzip them, and place them in appropriate folders.)

Compile the FitNesseRunner

In this example, we place the project in C:\Projects\FitNesseforDataFlex.

In DataFlex Studio, open the workspace “FitNesse Example Workspace\FitNesse Example.sws”

I  prefer to use precompilation, to reduce compile time. If you want to do the same, open the file FitNesseRunnerPrecompile.pkg in Studio, select Project -> Precompile -> Precompile Package <FitNesseRunnerPrecompile.pkg>.

Now compile the project itself, and upon running it, you should get the following message:

“No workspace has been specified. Start the program from FitNesse. Check the docs for further info.”

Now, close this message, and if a security warning appears, tell the Windows Firewall that it’s ok for fitnesserunner.exe to communicate on the network.

The program should now look like this:

fitnesserunner

But we haven’t started the FitNesse framework itself, so for the time being we will close this program.

Install FitNesse

From Fitnesse.org, you can download fitnesse-standalone.jar. This is a Java executable, so the Java run-time needs to be installed. The file goes into the FitNesse folder, i..e C:\Projects\fitnessefordataflex\FitNesse.

Finally, before you can run fitnesse-standalone.jar, you need to “unblock” it.

Run FitNesse

Run the batch file C:\Projects\fitnessefordataflex\FitNesse\StartFitnesse.bat

This will run fitnesse-standalone.jar, with the parameter -p 8081, instructing FitNesse to use port 8081. The first time you run FitNesse, it will create the folder FitNesseRoot, which is where the contents for the wiki is located, and where your tests will be located.

FitNesseFirstTime

You can point the browser to http://localhost:8081 to see that FitNesse is running.

FitNesseRunningFirstTime

But before you are ready to go, you need to tell FitNesse to use the FitNesseForDataFlex integration.

Setting up FitNesse to use FitNesseForDataFlex

Close the command line window that is running FitNesse.

Copy the contents of the folder “copy contents to FitNesseRoot after it has been created” to FitNesseRoot, and choose to overwrite existing files.

Run StartFitNesse.bat again, and point your browser to http://localhost:8081.

You will now see that there is a link to DataFlexTests.

DataFlexTests

Also, if you click on the root link at the bottom of the page, you will find that certain settings have been set:

FitNesseRoot

These settings tell FitNesse to use the Slim protocol, which exe file to run (TEST_RUNNER = FitNesseRunner.exe), which workspace the program should use (COMMAND_PATTERN), and finally the “classpath”, which is the class name prefix for the FitNesse fixture classes that will mediate between FitNesse and your production code.

Running your first test

Open the DataFlexTests page, and go to Division Test.

DivisionTest

Now, select the Test link at the top of the page. If all goes well, the FitNesseRunner will execute this test, exercising a DataFlex class called cFitnesseDivision, and calling the Quotient function with the parameters numerator and denominator given in the tables.

DivisionTestRun

You will see that the tests go green on the FitNesse web page.

Congratulations, you have successfully installed and run FitNesseForDataFlex.

Now it’s time to test your own software!

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

Programs/*.exe

Programs/*.dbg

Programs/*.exe.manifest

AppSrc/*.dep

AppSrc/*.prn

AppSrc/*.fld

AppSrc/*.pbg

AppSrc/*.pdp

AppSrc/*.pkd

AppSrc/*.prp

AppSrc/*.err

Data/*.cch

DDSrc/*.bak

Programs/Reindex.log

IDESrc/*.dsk

IDESrc/StudioMetaData.mtd

IDESrc/Workspace.loc

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).

Committing.PNG

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.