Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In Part 6 of this series I began rewriting some of the embed code from the UpdateDetail procedure in the Invoice app as a reusable, testable class. Although I simply showed some test code on its own, that code lives inside a ClarionTest-compatible test DLL.

...

In the Select Procedure Type dialog click on the Defaults tab and choose Test Procedure (Figure 5).

Image Removed

...

. Make sure you're on the Defaults tab, not the Templates tab!

Image Added

You'll notice that the procedure properties have been preloaded with a prototype and parameters (Figure 6). Do not change these values or the test procedure will not work , and may cause a GPF in CTest ClarionTest or your DLL.

Figure 6. Properties for the test procedure

Now, right-click on the procedure and choose Source to bring up the Embeditor (Figure 7).

Image Removed

...

There really are only two embeds you need to be concerned about in the test procedure. One is the data embed, where you declare any data you need for the test. The other is Priority 5000, right before the return statement. That's where you place your test code.

Here's the code for the data embed:

Code Block
detail  InvoiceDetail

And here's the code for the source embed:

Code Block
    detail.Init(12.50,3)
    

...

AssertThat(detail.GetExtended()

...

,IsequalTo(37.50

...

),'Wrong detail value')

Once you've entered the code your test procedure should look like this in the embeditor:

 Image Added

Save and compile the DLL. You'll get something like seven errors.

Clearly there's a problem because you haven't yet defined the class!

...

An easy way to create classes

There are a number of different ways you can declare classes in Clarion; some of them are fraught with danger. For instance, if you create classes that you export from a DLL so they can be used elsewhere, you had better get everything just right or you'll probably be looking at GPFs.

The approach I'll show you is the simplest, most foolproof way I know to create classes in Clarion and still reuse those classes everywhere you like.simple and lends itself to class reuse - it also makes it easier to move your classes into a DLL in the future should you want to do so. 

 

 

 

 

First, add a new Clarion source file to your test DLL project (you can move it later). Now, adding a new source file to C7 via the solution explorer is pretty buggy.

...

You should now be able to compile the DLL.

Setting up

...

ClarionTest

There's one more thing you should do now to make unit testing as painless as possible, and that's to set up CTest ClarionTest in the C7 Tools menu. Choose Tools | Options, and from the list of Options choose Tools again. Click on Add to create an new external tool entry. Set the Command field to point to CTestClarionTest.exe, and set the Arguments field to ${TargetPath} as in Figure 8.

Image Modified
Figure 8. Setting up

...

ClarionTest as an external tool

With the test DLL as the active window in the IDE, choose Tools | Run unit tests. You should see the CTest ClarionTest window with the test DLL loaded, as in Figure 9.

Image Modified
Figure 9. Loading the test DLL

...

Press the Run All button. You should see a test failure, as in Figure 10.

Image Modified
Figure 10. Test failure

GetExtended just returns zero. Change the class code to store the price and quantity in private variables, as follows:

...

Compile the DLL.

If you exited the CTest ClarionTest application, restart it from the Tools menu. If you still have it up just press Reload. Then press Run All. The test should now pass.

...

And what do you know - it works!

Image Modified
Figure 11. Two tests pass!

...

Figure 12 shows the remainder of the tests, which while not yet exhaustive do a reasonable job of covering the bases.

Image Modified
Figure 12. The test suite

...