Decision Management (ODM,ADS)

 View Only
Expand all | Collapse all

how to unit test individual rule

  • 1.  how to unit test individual rule

    Posted Tue February 28, 2023 08:34 AM

    Hello,

    i know we can use test suite to test the ruleset.
    but how do we unit test individual rule? how to do trigger CICD to unit test the rules?
    it seem like there is not so obvious way of doing it.



    ------------------------------
    Goh Kian Seng
    ------------------------------


  • 2.  RE: how to unit test individual rule

    Posted Wed March 01, 2023 03:17 AM

    Hi Goh,

    It is normal practice to test a ruleset using Decision Runner, and scenario testing, but if you need to do unit testing i.e. test each rule one at a time, you can do it using runtime rule selection. The steps are:

    • Create a ruleflow with a single task and add all the rules to the task
    • Create a string variable called the fully qualified name of the rule
    • Add runtime rule selection to the task, so that only one rule is selected for evaluation based on the value of the variable
    • Map the variable to a IN ruleset parameter
    • Generate a test suite using Decision Runner
    • Add the name of the rule to the test to define the target rule to unit test in the spreadsheet, along with your unit test data.

    Using runtime rule selection in this way will ensure only the target rule gets selected for evaluation.

    It is fiddly to initially set up, but once you get it going it is straight forward. You will of course end up up with a very large number of tests. And you are not testing how rules interact together for which you need scenario testing.

    FYI I used this approach to unit test Modified Cored Types in ODM Accelerator 

    Hope this helps.

    Peter

    Mobile:  France +33 753 423 222  UK +44 (0)7446 092554


    ------------------------------
    Peter Warde
    peterwarde@rulearchitect.com
    ------------------------------



  • 3.  RE: how to unit test individual rule

    Posted Wed March 01, 2023 03:19 AM

    Hello,

    there is no built-in feature to test a single rule. The unit of work is a ruleset.

    If you really want to test one or a few rules (a subset of the full ruleset that would go to production), you can create a dedicated Decision Operation for testing, along with a dedicated ruleflow, that is only selecting the subset of rules. 



    ------------------------------
    Antony Viaud
    Product Manager, IBM Decision Automation
    ------------------------------



  • 4.  RE: how to unit test individual rule

    Posted Tue March 07, 2023 04:02 AM

    Hi Mr Antony,

    we have close to 3k plus of rules. to maintain 3k of rules set will be a nightmare for us.



    ------------------------------
    Goh Kian Seng
    ------------------------------



  • 5.  RE: how to unit test individual rule

    Posted Wed March 01, 2023 05:16 AM
    Edited by Peter Warde Wed March 01, 2023 06:03 AM

    Hi Goh

    Here is what you need to add to the runtime rule selection on the ruleflow task:

          String modName = ?rule.name.replaceAll("\\$", "");
          modName = ?rule.name.replaceAll("_", " ");
          return modName.equals(offerTest.targetRule.trim());

    The first 2 lines clean up the the fully qualified name of the ODM rule. The last line selects the rule to be evaluated ('offerTest' is the ruleset parameter variable and 'targetRule' I added to the BOM and is the name of the rule to evaluate).

    In my Decision Runner test Scenario I added the name of the rule I wanted to test as follows:

    It works :-) !

    Peter




    ------------------------------
    Peter Warde
    peterwarde@rulearchitect.com
    ------------------------------



  • 6.  RE: how to unit test individual rule

    Posted Tue March 07, 2023 04:06 AM

    Hi Mr Peter,

    this seem working i would like to test it out on my environment.
    will get back to u once we got it :) thank u

    hope u can advice me on how to import excel(test suites) into ODM decision center :)
    i guess this is the last piece of puzzle to get the best out of ODM



    ------------------------------
    Goh Kian Seng
    ------------------------------