...
In Part 1 of this series I examined the architecture of Clarion applications; in Part 2 and, Part 3 I examined some of my own code for parsing TXAs to extract embed code and showed how to make that code into testable, reusable classes. In Part 4 I reused my classes to create an embed viewer utility app.
In Part 5 I reintroduced the Invoice.app that ships with the Clarion examples and I demonstrated the buggy nature of the invoice line item calculation code.
...
But .NET unit testing tools benefit from some .NET language features, particularly reflection. A .NET unit test framework can inspect an assembly, locate test methods inside test classess, run those test methods and report on the results. That's a lot more difficult to accomplish in Win32.
Unit testing in Clarion Win32
I wasncouldn't aware of find any third party unit testing tools for Clarion, so I went ahead and wrote one. Actually this tool is in two parts: an executable application (called ClarionTest) that will search a DLL looking for unit tests to run, and a set of supporting templates you use to create test procedures in a test DLL that is compatible with ClarionTest.
Figure 1 shows the ClarionTest application with a test DLL loaded and several tests having been run (this screen shot is from Part 2). As you can see, ClarionTest is just a single window application that lists the available tests, lets you run those tests, and shows you the results.
Figure 1. The ClarionTest test runner
The Test_
prefix is necessary for ClarionTest to identify the procedure as a test procedure (this way you can mix test and non-test procedures in the DLL).
I'll get into the specifics of how to use ClarionTest and the test procedure template shortly (and I'll have an article on ClarionTest later this month).As I mentioned earlier in this series, ClarionTest is included in the freely available DevRoadmaps Clarion Library (DCL).
To recap, here are the stages I've completed:
...
Having said that, even after you become proficient in creating unit tests you almost certainly will spend more time up front creating your code than you did writing embed code. It takes time to write good tests. But there's also a huge payback , in the form of fewer bugs, more confidence and better reusability.
Creating a test DLL
I'm using Clarion 7 in the following explanation, mainly because it lets me create a single solution containing both the original application as well as my test DLL.
First, copy the ClarionTest.TPL file from the downloadable source into your Clarion template directory and register it. This template contains the test procedure template as well as a global extension you'll need for the test application.
The downloadable source zip contains all the projects you need (including the ClarionTest project). Or if you're following along you can work directly with the Clarion Invoice application. I'm using the C6 version which I've converted to C7.
If you're using your own solution, right-click on the solution in the Solution Explorer and choose Add | New Application or Project. Choose a type Application (not DLL) from the dialog (Figure 2).
Figure 2. Adding a test DLL to the solution
In the Application Properties dialog set the Destination Type to DLL (Figure 3).
Figure 3. Creating the test DLL
You don't need the Application Wizard since you'll be creating all your procedures manually.
You do however need to add a global extension to the DLL to enable the unit test support code. On the Global Extensions tab click on Insert, and choose Class Clarion Test | TestSupportIncludes (Figure 4).
Figure 4. Adding the TestSupportIncludes global extension
You're now ready to create your first test procedure, and I'll cover that topic next time.