RPG Next Gen
Wiki RSS Feed Weblog
Business picture

Unit Testing for RPG


This page will not tell you what a unit test is or how test driven development works. There are numerous sites out there which explains that way better than I can. So please visit them first and then come back to learn how you can enhance your RPG skills with unit tests and make your life as a software developer a little easier.

Nice to have you back. Now that you know what unit testing is we can start learning how it can be applied to RPG. Fortunatly there is already a project which has done most of the things we try to accomplish. Take a look at the RPGUnit project at Sourceforge.net. The software is provided in the archive file in the download section. And the installation instructions on the web site are really good. The tutorial is also well written and shows you how to write a unit test in RPG.

By now you'll probably know how to write a unit test in RPG and ask yourself what this page is really about.

Project Goals

The software from the Sourceforge.net site is intended to be used as a standalone product. It has some commands to be executed from the command line. The test result is outputted to the screen and to a spooled file. This is not very convenient for the developer who uses the RPG Next Gen Editor (or RDPi/WDSc). It also supports no continous integration.

This is what this page is about. I'm adding RPG unit testing to the RPG Next Gen Editor and also add automated unit testing to a continuous integration server like Hudson.

RPG Next Gen Editor Plugin

The plugin for the editor enables the developer to execute one or a whole suite of unit tests from the Remote Explorer (by right clicking on a unit test service program). The results will be shown in an extra view.

Unit test objects are identified by their user defined attribute which must have a value of RPGUNIT. The value is automatically set on unit test creation with the command RUCRTTST. If a unit test is created manually the user defined attribute can be set with the programm RUUPDOBJD. The syntax for the program call is:


Other software may set their own user defined attribute value on their managed objects. So please check the value before using the update program (f. e. with the DSPOBJD command).

The plugin is shipped with the RPG Next Gen Editor version 0.5.5. The IBM i programs can be obtained from the download section. For installation instructions see the RPGUnit home page. You can start with the Compile the framework as the RPGUnit is packaged as a save file on my site. It needs the service program Linked List in the library list for compilation and usage.

The RUNUNITEST rpg program is missing in the save file. You can get it here.

Continuous Integration

It would be nice to know if someone on your dev team broke some peace of software with his latest changes on a program, either not compiling at all or not behaving as it should. This is where continuous integration servers jump in.

A continuous integration server lets you build part or all of your programs (as configured) and executes all configured unit tests. If somethings goes wrong you'll be notified via email.

My continuous integration server of choice would be Hudson as it is very easy to setup and configure. You need to download just one file and are up and running in minutes. It mainly uses ant for executing things. As ant is very flexible it can do anything (more or less). The first step of this goal is to provide a way to execute RPG unit tests from within Hudson and the second would be to let Hudson compile one or more programs/serviceprograms.