Sub-procedures in a service program allow easy unit testing. Just create a program that walks through the scenarios that you want to test. Using a tool like RPGUnit will help. Then run the unit test any time you make a change.
Rory makes a good point though, you may not be able to test all the valid scenarios unless there is a finite number of valid combinations. If all the fields involved in the validation have a set list of acceptable values, then you can build a test for them. If all the fields involved in the validation have a set list of invalid values, then you can test for that. But, if any of the fields can have an infinite number of valid values (even if it is validated from a table), then you just have to throw in a few tests that are not invalid to exercise the code. If you are using RPGUnit to facilitate unit testing, then you have to re-visit your tests any time you make a change to the tested sub-procedure. This is to make sure the tests are still all valid, and that you don't need additional tests to work out the changes you made.
Mark Murphy
STAR BASE Consulting, Inc.
mmurphy@xxxxxxxxxxxxxxx
-----rpg400-l-bounces@xxxxxxxxxxxx wrote: -----
To: rpg400-l@xxxxxxxxxxxx
From: Pete Hall <pete@xxxxxxxxxxxxxx>
Sent by: rpg400-l-bounces@xxxxxxxxxxxx
Date: 01/15/2010 08:36PM
Subject: Re: Test Advice for a function
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
David FOXWELL wrote:
Hi,
I have a really simple function that allows or limits the access to a transaction for a client, depending on the kind of contract, kind of product, etc, etc.
The function receives the different types of product, etc, and compares them to constants, then returns on or off. Simple. There are about 10 different combinaisons that are restricted, all others pass ok.
My question is how to properly test that function? I could easily select clients with all prohibited contract types, products, etc, as these are only a few. How should I test all those types that are NOT prohibited?
Thanks.
How about a bit mask?
Each byte in a key value consists of a value related to one of the
attributes. Byte 1 could be contract, byte 2 product etc. At the end of
building the requirement, you'd end up with x'A02AB9884C' or something
like that. The attributes would need to be in a known order. Then you
just need to compare with a table containing the 10 forbidden
combinations and see if you have a match.
- --
Pete Hall
pete@xxxxxxxxxxxxxx
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAktRGCcACgkQXczQcKdXKg7tOgCgs5S5IHfBU3qa+iRcXF5cJ1DQ
s8sAnj9680mQdkTd12KpqyF+68WbMfTl
=838H
-----END PGP SIGNATURE-----
As an Amazon Associate we earn from qualifying purchases.