INNOVA Solutions



Dunit Testing at Innova Solutions


Presentation by Roger Connell at ADUG Melbourne August 2015

Roger contributed to the ADUG discussion about how unit testing is used by members.

At Innova Solutions any test jig required to exercise or debug a function or object is written as a DUnit class. These are then incorporated into generalised tests suits which make them available as regression tests when a new version of Delphi is released. It is also helpful when you need to change something to be able to run the original tests.

In some cases we do write the test case first and then use that as a test harness while we refine the function or object code but given the vintage of much of our legacy library in most cases the test case is written to first demonstrate a bug and then to step through the code to make the repair

Our tests include Internet polling, inter-process synchronisation, database access and Delphi based connection to Microsoft Word, Access, etc.

Unit Testing Pros

  1. Makes it easy to set up a test harness.
  2. Repeatable exercise of code.
  3. The test case provides a record of the original and progressive functionality expected of the tested item often documenting intent.
  4. Can use the features of break point groups to enable breakpoints only during critical processing.

Unit Testing Cons

  1. There is cost and effort in establishing unit tests.
  2. If testing gets complex maintenance of the test code becomes significant. In our case the hardware and directory structure and the operating system can cause problems with tests and there is a need to make sure all data required to run the test is in place.

Some Features of Innova Test Cases

  1. Launches an external program to test locks from a separate process
  2. To enable end to end testing of the database interactions our remote database tests are setup enable the option of running the server code (normally a service) inside the test case.
  3. Creates database, renames or deletes files to assist tests.
  4. We use compiler defines to change interfaces in the main library code from Windows socket communications to one using Indy. At this time most test run successfully under both regimes but the large object transfers which tend to take minutes fail using Indy as we have not yet resolved some watch dog issues.
  5. We have also a FireMonkey Unit Test GUI which allows DUnit tests to be run on MAC and hopefully other platforms to prove out cross platform library functionality.

Hints

  1. You may need to insert delays to allow windows to “catch up” eg after a file rename or delete.
  2. When Debugging the Group Breakpoints together with non-breaking activation/deactivation are useful to start breaking only on a specific test.

Good testing Practice

We do not follow what we now understand to be “good unit testing practice” this is not because we reject these practices but because we have developed our tests over time and a retrofit would not be cost effective. Good practice discussion points

  1. Each test should stand alone with set up and tear down for each test
  2. All functions and code paths are tested
  3. Write test specification first then write code

Code Examples

A Zip file of a project containing one simple test case from our suit together with the tested source code is available here. The tested object is a simple log file object and the test case checks the ability to roll logs and purge outdated logs.

While it is not possible to offer our actual test projects for download as they by definition require access to our complete code library it is thought that the actual test cases might help others understand our approach and are made available. The source for an extensive set of Innova Test Cases below but they do not include the library source which would be required to compile them.

The general library test cases are contained in DUnitTstCase.pas and DUnitTstCaseUniCode.pas.

The cross platform persistent object database test cases are in DUnitTstCaseCrossPlatform.pas and the test database objects are in LibTstNewCrossPlatformObjs.pas and LibTstNewPermRemObjsCrossPlat.pas. Object database details are available via http://www.innovasolutions.com.au/delphistuf/ADUGSymposium2008.htm.

These test cases also run under the Firemonkey unit testing frame work discussed at ADUG in December . http://docs.innovasolutions.com.au/Docs/ADUGDelphi/ADUGDecember2014.html. At this stage the persistent local database has been demonstrated via unit testing on the MAC but more work is required the get the remote db code working when significant transmission times are involved.

Other Innova Solutions Presentations at ADUG

ADUG Presentations


The company accepts no liability for any alleged or actual damage arising from the use of any of these products or this information.



For feedback on this information contact us :: enq at innovasolutions.com.au
 


Home           Australian Delphi Users Group

INNOVA Solutions Pty Ltd - ACN 081 449 836