IBMiUnit Moves RPG Unit Testing Forward
June 24, 2020 Alex Woodie
As IBM i shops break up their monolithic programs into more reusable chunks, it’s reasonable to assume that they would adopt unit testing to make sure those chunks are working properly before promoting them into production. Unit testing hasn’t been widely adopted on the IBM i platform, which is why RPG developers who are looking for a unit testing tool may be interested in a new framework called IBMiUnit.
IBMiUnit is an open source project that helps programmers test any RPG-based program, subprocedure, or method, including RPG-based SQL. The software, which is modeled off the popular JUnit and xUnit frameworks, lets users build repeatable test cases that they can run periodically to ensure that the code is behaving as expected and not returning errors.
The software was created by Marina Schwenk, a developer who works at the Wisconsin lighting manufacturer Everbrite and who was named a 2019 Fresh Face. Schwenk decided to develop IBMiUnit in 2017 after using JUnit on a Java project at Everbrite and finding there was no equivalent testing framework for RPG.
“We looked . . . and the best thing we saw was RPG Unit,” she says in a recent COMMON iNSIGHT presentation titled ‘Intro to Unit Testing RPG Using IBMiUnit.’ It had not been updated. It has since then, but not then.”
Schwenk was quite happy using JUnit for her Java development, and was not thrilled that she wouldn’t have a similar tool to help guide her RPG development efforts. She hacked a method in JUnit that allowed her to call an RPG program from Java, but she knew that wasn’t going to cut it. With the proverbial unmet need hanging right in front of her, Schwenk grabbed opportunity by the C-spec and decided to do something about it.
“We needed something that’s going to work not just for us but for the industry,” Schwenk said. “Both myself and my mentor knew that we wanted to do something that the community could use. We wanted to take the concept of unit testing and really bring it out to the [RPG] community, because we saw so much of the benefit to it, as a developer, with it streamlining our process . . . strengthening our development. We believed in it so much that we wanted to bring it out to the community, so that’s what started IBMiUnit.”
Schwenk and her mentor at Everbrite had some design goals in mind for IBMiUnit. First, they wanted automated, repeatable testing, something that could allow developers to run tests over and over again. They wanted to be able to test external interfaces. And most importantly, they wanted IBMiUnit to follow industry standards.
“JUnit and IBMiUnit were both written using the industry standard of xUnit,” Schwenk said. “That’s the top unit testing framework and everything else is a branch of that framework. We saw what xUnit was doing. We saw what JUnit was doing, and then we made sure we implemented that into IBMiUnit.”
Developers get started with IBMiUnit like many open source projects these days: by downloading the repository from its GitHub site. The project is composed of several run-time and compile-time objects, as well as greenscreen user interface where users interact with the software and view results.
Once the software is installed and initialized, developers can start creating test cases in IBMiUnit. After naming the Developers must specify the parameters that the program or subprocedure is expected to return. When IBMiUnit runs the unit test using test data, and the test does not generate the expected result, then IBMiUnit will return a failure notice. If everything runs as expected, the user gets no feedback.
IBMiUnit includes several types of built-in unit tests, including: indicator tests (where the result is on or off); pointer tests (where the results are null/notnull); and variable tests and comparisons using characters, dates, floating point numbers, numbers, time, and timestamps. Users can specify the delta, or the leeway in allowable differences for values, for some types of tests, or configure IBMiUnit to generate a failure notice if exact values are not returned.
“Anything that your procedures inside of a service program is doing, you can test it,” Schwenk said. The one RPG element that it cannot test are subroutines.
Developers can also bundle multiple unit tests into a single job with IBMiUnit. “The logic varies on what you’re doing,” Schwenk said. “You can have a test for a procedure call another procedure with test data, then call the program or procedure, then compare the actual results when it comes back.”
Interest in IBMiUnit is building. The project has 14 stars on GitHub, and is gaining more contributors, including fellow Fresh Face Liam Allen, who introduced a new installation option for IBMiUnit. Looking forward, Schwenk plans to bolster IBMiUnit with additional functionality, including better support for SQL scripts as well as XML output.
“We’ve got it pretty solid right now. But we want to build on that,” she said. “We want to add functionality to it where it behaves a lot like JUnit or xUnit works.”
Schwenk developed IBMiUnit to help her create better code at her job, and the whole community can now partake of that effort. As more RPG developers adopt modern coding methods, she expects unit testing – via IBMiUnit – to play a bigger role.
“It’s really going to help you in your development process,” Schwenk said. “It will, over time, cut down on the fires, especially if you have older monolithic code. You’re not going to be able to take unit testing and dump it over 20,000 line code. But as you start breaking up that big monolithic program into smaller, manageable pieces, unit testing is really going to help you.”
Is there any association to RPGUnit or iRPGUnit (i “think” iRPGUnit uses RPGUnit core library)?