Update (10.04.2012): NUNIT (now NatUnit) is now available via SourceForge: NUNIT/NatUnit at SourceForge.
As part of my Master’s thesis about Test Driven Development (TDD) I developed a Unit-Test-Framework for the programming language Natural. This 4GL language from Software AG is in use for over 30 years now but the notion of automated tests has not been spread throughout the developer community. Perhaps now, with a framework for tests available, this will change 😉
The Unit-Tests that can be run by NUNIT are subprograms and need to have the following structure. As you can see, the fixture’s and tests’ names are simply plain text to allow strings that are longer than 32 characters (the longest possible name for a Natural module) to provide meaningful names as in Behaviour Driven Development. The TestCases are parsed by NUNIT for this structure to make sure that all the needed parameters, subroutines etc. are available. To create a new TestCase all you have to do is copy the example source code and change the names and the implementation of the tests in the IF-branches.
DEFINE DATA
PARAMETER USING NUTESTP /* parameters for a single test
LOCAL USING NUCONST /* NUNIT constants (error code etc.)
LOCAL USING NUASSP /* parameters for the assertions
END-DEFINE
*
NUTESTP.FIXTURE := 'Example TestCase 1' /* this TestCase's fixture
*
INCLUDE NUTCTEMP /* the template method (SETUP -> TEST -> TEARDOWN)
INCLUDE NUTCSTUB /* stub implementations of SETUP and TEARDOWN
*
DEFINE SUBROUTINE TEST /* the main test routine
*
**************************************************************
IF NUTESTP.TEST EQ 'comparing two equal numbers should pass' /* name of first test
**************************************************************
ASSERT-LINE := *LINE; PERFORM ASSERT-NUM-EQUALS NUASSP 2 2
END-IF
*
**************************************************************
IF NUTESTP.TEST EQ 'comparing two different numbers should fail' /* name of second test
**************************************************************
ASSERT-LINE := *LINE; PERFORM ASSERT-NUM-EQUALS NUASSP 1 2
END-IF
*
END-SUBROUTINE
*
END
The following diagram shows NUNIT’s architecture. I tried to make the adaption of NUNIT to a different platform than ours (Solaris with Natural modules saved in the file system) as easy as possible and encapsulated the OS-specific implementation into two modules that need to be changed accordingly. I have also included some basic assertions like ASSERT-NUM-EQUALS, ASSERT-STRING-EQUALS and ASSERT-ARRAY-EQUALS and some example TestCases in the source code you can download below.
The TestCases’ names are defined in a user-specific workfile in the home directory (in the current configuration, but this may be changed e.g. to a DB READ). A run of all defined TestCases is as simple as calling the main program NUNIT and produces an output like the following (even with a “red bar” 🙂 ).
Notice the nice failure/error messages including the module names, line numbers etc. 😀
I developed NUNIT by applying TDD which means the framework tests itself. After you “installed” it (which means importing the NUNIT modules into a library of your choice, preferably a steplib if you plan on using it throughout your application) you can run a simple TESTNU to make sure NUNIT behaves as expected.
All NUNIT modules include a detailed header comment so they should be pretty self-explanatory. But in fact, all you need to start are the programs TESTNU, NUNIT and NUSINGLE (with which you can run a single TestCase) and a TestCase like TCEXMPL1. Just try it out and let me know if you like it 🙂
Downloads