You are viewing the documentation for Blueriq 14. Documentation for other versions is available in our documentation directory.

Table of contents

What is it?

A unit test tests a piece of business logic, just as a quick test does. The unit test however is saved in Blueriq Studio and can therefore be repeated.

What does it do?

A unit test defines input (profile) and the expected output for a specific attribute. The unit test is saved and can be repeated, allowing to test business logic if changes are made. Also a unit test can be used as a form of documentation. By defining input and expected output, the functional operation is documented.

Unit tests are different from quick test on the following points:

  • A unit test contains an expected output
  • A unit test can contain multiple input profiles that should lead to the same output
  • A unit test is saved

How to – create a unit test

There are two ways to create a unit test:

  1. Create a new unit test from the unit test overview screen of an attribute
  2. Via the Test tab > General group > Unit test button

Create a unit test from the unit test overview screen

  1. Open the unit test overview screen for an attribute. This can be done by clicking the unit test overview button from the attribute itself or from any decision table or business rule where the attribute is derived.
  2. Select the module in which you want to create the unit test
  3. Click the Create unit test in module button

Create a unit test from the ribbon

  1. Select the Test tab
  2. From the General group select the Unit test icon
  3. Fill in the required fields, tick or uncheck the necessary boxes on the unit test screen
Databox

Datafield

Function

Definition

Name

Identifies the object. Maximum 50 characters (only letters, numbers and underscores (_)) are allowed.

Definition

Functional name

Optional, can be used in documentation

Definition

Description

Optional

Definition

Attribute

The attribute that is going to be tested. By clicking the unit test overview button the unit test overview screen is opened for that attribute.

Run test

 

Allows running the unit test and shows the result

Profiles

 

The input for the tested element, represented as a profile. A unit test can have multiple profiles. Each of them can be imported, copied and/or edited to create the desired input.

Expected values

 

The expected value of the attribute given the input (profiles)

Generate profile input

Creating a profile can be a lot of work. To make this easier, Blueriq Studio has functionality to generate a profile. Blueriq Studio tries to derive an attribute with an empty profile and shows the attributes required in the derivation. These are shown in a source tree, which in turn can be edited to create the desired profile.

 

To generate a profile:

  1. Choose Generate profile from the profile buttons

  2. Blueriq Studio tries to derive the specified attribute. The minimal set of attributes that is required in the derivation is shown in the source tree. If it is possible to derive a value, that value is shown in the Result databox.

  3. The source tree can be edited by editing the values of the attributes. A value can be added or edited with the edit icon and cleared with the clear icon. When a value is changed, Blueriq Studio automatically tries to derive the attribute with this new value and shows the result.

  4. If enough information is filled in and the derivation is successful, you can save the created profile by choosing the Generate profile button.

Create multiple profiles

Sometimes different inputs for a unit should lead to the same output. To prevent having to make many different unit tests actually testing the same result, multiple profiles for one unit test are supported. This makes it possible to assign different profiles to one unit test, all leading to the same output.

The profiles are listed in the Profiles databox. Each profile can be edited. The summary is automatically generated based on the number of instances in the profile. The target instance determines the starting point of the inference mechanism to determine the value of the attribute by the bussines logic that is defined for that attribute. It is possible to use a profile for a quick test by clicking the quick test icon.

Profiles can be generated as described above, but also manually edited, copied from other unit test or imported. This works the same as with quick tests.

Run a unit test

Running a unit test means checking if the result of the unit test, given the input profile(s), matches the expected output. There are two ways to run a unit test:

1. from the unit test itself

2. from the unit test overview screen

Run a unit test from the unit test itself

A unit test can be run directly from the unit test itself in the Run test databox. By clicking the Save and run unit test button, the unit test is first saved and then executed. If the unit test succeeds, meaning that for all profiles the output is as expected, the results simply show that the unit test succeeded.

If the unit test fails on one or more profiles, for each profile the expected output and the actual output is shown.

It can happen that the expected value has to be updated due to changes made to the business logic. Logically, your unit test will fail if this is the case. You can simply update the expected value from the unit test result by clicking the update expected value button. This will overwrite the expected value with the actual outcome of the unit test given the selected profile.

If a unit test fails, only the actual outcome is shown, not how this value is derived. To show the derivation, you can run a quick test from the profile which failed, which will show you the source tree.

Run a unit test from the unit test overview screen

Open the unit test overview screen for an attribute and click the run button. All the unit tests defined for the attribute will be executed and the result (Failed or Succeeded) will be shown.

If a unit test fails, you can open it to see for which profile the actual output was different than expected.

Run all unit tests in the module

Unit tests inside the module scope can be run in a single batch from the Test tab in the studio ribbon.

When pressing the button all unit tests that are in the module scope will be run at once. A new window will appear showing the test results listed per unit test. An icon is displayed indicating whether the unit test failed or succeeded, Clicking on a unit test shows the profiles with expected and actual values. Clicking on the title of the test in this window will open the actual unit test.