📖
Rulecube documentation
v2.4
v2.4
  • Overview
  • Quick Start
  • Tutorial
    • Getting started
    • Create and Run Your First Ruleset
    • Use Constants and Methods
    • Create and Call Functions
    • Adding Testcases
    • Using Lookup Tables
    • Using Entities
    • Using Forms
  • How-to Guides
    • Logging in and Authorization
      • Activate Your Account From an Invitation
      • Log in to Rulecube
      • Change Your Password
      • Recover Your Password
      • Two-factor authentication (2FA)
      • Invite Other Users to Rulecube
      • Edit a User's Role
      • Delete a User
    • Ruleset Development
      • Create a Ruleset
      • Set the Input for a Ruleset
      • Create a Rule
      • Generate Alerts
      • Try out a Ruleset
      • Call a Ruleset from Your Software
      • Entities
        • Create an Entity
        • Drag and Drop a JSON Schema or XSD to create entities
        • Entity instantiation
        • Persisted Entities
      • Constants
        • Constant Tables
      • Functions
      • Built-in Functions
      • Create and Run a Testcase
      • Delete a Ruleset or Components
      • Debugging your Ruleset
    • Create a Workflow
      • Workflow step types
      • Working with documents in a workflow
    • Work with (Environment) Variables
    • Call a Ruleset via Its API From Postman
    • Creating input from JSON Schema
    • Use a Ruleset from Your Software
    • Ruleset Productivity Tips
    • Create an Ockto workflow
    • Alert aggregation
    • Forms
      • Introduction and overview
      • Create a Data table
  • Language Reference
    • Global
    • Array
    • Compression
    • Crypto
    • Date
    • Encryption (deprecated)
    • Finance
    • Http
    • Mail
    • MongoDB
    • Ockto
    • PDF
    • SQL
    • Statistics
    • System
    • UserStore
    • Workflow
Powered by GitBook
On this page
  • Introduction
  • Task: Create a Testcase
  • Task: Fix the InsuranceCosts rule
  • Task: Fix the InsuranceCosts rule again
  • Recap
  1. Tutorial

Adding Testcases

PreviousCreate and Call FunctionsNextUsing Lookup Tables

Introduction

In the previous tutorials we've been developing our ruleset and trying it out in the Sandbox to test it. Now that we've got a ruleset we're happy with, we want to make sure that it will continue to work as intended. We'd like to be notified when a change to our ruleset unknowingly changes its output.

Rulecube has a mechanism for this: Testcases.

Task: Create a Testcase

  1. In the left menu, click on the + Next to the Testcases menu section

  2. You should be presented with a new Testcase like this:

A Testcase consists of two parts, similar to the Sandbox: Input and Expected output. What we'll be defining here is "when this goes in, this should come out".

Let's first set the input:

  1. Change the value of StartDate to: 2023-07-20

  2. Change the value of EndDate to: 2023-07-27

  3. Change the value of NumberOfItems to: 2

  4. Change the value of DateOfBirth: 1990-01-01

  1. Go ahead and press the create baseline button

This should result in the following:

Rulecube has determined that for the given Input, this is the Output.

Now what happens when the Expected output doesn't match the actual output? Let's say that an travel insurance expert looks at the Input of this Testcase and determines that the InsuranceCosts in the Output should actually be 4 in this case!

This means that somewhere while making our ruleset, we've made an error or we forgot something in our calculation!

Let's trust the travel insurance export for now:

  1. Change the InsuranceCosts in Expected output to 4

  2. Save the ruleset

Note how the Testcase is run automatically when you save. It should now show a failure:

Rulecube has detected that the expected output no longer matches the actual output. Now let's see how we can fix the InsuranceCosts rule so that it will match the expected output.

Task: Fix the InsuranceCosts rule

  1. Open the InsuranceCosts rule

It seems we've missed something from our expert's specification! We need to always add 1 to the result to offset the insurance costs. Let's fix that!

  1. Change the expression to the following:

    1 + ROUND(RiskCostsPerDay.get(RiskCategory) * NumberOfDays + AgeSurcharge(Age, NumberOfDays))
  2. Save the ruleset

When the ruleset has been saved, the Testcase should succeed and the failure banners should disappear.

Task: Fix the InsuranceCosts rule again

The travel insurance expert just informed you that the insurance costs offset should actually be 10, not 1!

Let's implement this change to our code.

  1. Open the InsuranceCosts rule again

  2. Change the 1 at the start of the expression to 10

  3. Save the ruleset

As you might have expected, this will break our Testcase once again. Let's open our Testcase 1.

We could manually fix the value for InsuranceCosts here to match the actual value 13. An easier way is to press the CONSOLIDATE button below it. This will automatically change the expected output to match the actual output.

  1. Click CONSOLIDATE

    1. Alternatively, manually enter 13 into InsuranceCosts output and Save

The ruleset should automatically save and re-run our Testcase. If all goes well, the Testcase should once again succeed!

Recap

We've learned how we can create Testcases that will allow us to make sure our rulesets work as expected. It will also notify you when a ruleset is broken by a change in the ruleset or its dependencies.

Once your ruleset reaches a certain level of complexity, it is recommended to add testcases to it and to not rely on manual testing in the Sandbox anymore.

Now we need to define what we expect ElectronicDeviceCosts and InsuranceCosts to be. We could manually fill this in, but since this our first time with this Testcase, we can create a so-called baseline by clicking this button: (next to the Reset button under Expected output fields).