The current document tries to explain what is Unit Testing and how to implement Unit tests within an Axional Studio application context.

1 Introduction

1.1 What is it

Unit tests are typically automated tests written and run by software developers to ensure that a section of an application (known as the "unit") meets its design and behaves as intended. In procedural programming, a unit could be an entire module, but it is more commonly an individual function or procedure.

For example, imagine that it has been implemented the function fnMultiply for multiplying two factors. So, the function would receive two paremeters, the multiplicand and the multiplier, and return a value corresponding with the multiplication of them, the product. It would be interesting to have some tests that evaluates that for certain pairs of factors the function returns the correct product:

Multiplicand Multiplier Product
2 3 6
2.5 2 5
-2 3 -6
-2 -3 6

The main advantatges of including Unit tests in an applicacion development cycle are:

• Unit testing isolates each part of the program and shows that the individual parts are correct.
• Unit testing finds problems early in the development cycle.
• Unit testing allows the programmer to refactor code or upgrade system libraries at a later date, and make sure the module still works correctly.
• Unit test cases embody characteristics that are critical to the success of the unit.

TEST SET

Each instance of the junit_script_base is call Test Set. The Tets Set can hold one or several test call functions, called Test Units, usually releted by subjects or by the need of executing a sequence that can not be verified individually.

1.2 What can I do

In the Axional ERP application context, refers to the business logic code stored in dictionary modules:

• Database architecture: Tables, indexes, constraints, etc.
• Database programs: Triggers, procedures and functions.
• Axional Studio Scripts: XSQL-Scripts and server-side Javascripts.

1.3 What do I need

Unit tests can be executed in several ways. The simplest way of implementing a Unit test is to create a test function or procedure that executes the target function or procedure and evaluates its results. Despite of the ease of implementing Unit test this way, the tests results bad organized, functional code and test code are mixed; so, it is harder to read and does not allow automatization. Consequently, it is not recommended to use this method for implementing Unit tests.

Another way of implementing Unit tests is using external applications. It exist a wide range of testing applications in the Market (Selenium, Cypress, JMeter, Soap UI, etc). These applications offer amazing functionalities, mainly for tests organizing and automatization. The major problem is that they require an advanced knowledge about the application architecture and its core functionalities. As Axional Studio is a framework which isolates the software programmer from the application architecture, with the objective of focus on functional programming, these CORE and architecture functionalities are generally unknown by the programmer and some are even restricted for security. Another problem that arises from using external applications is that testing programs are very far from the functional code, which lead that the tests are left unattended and become obsolete. Having all of these in consideration, it is not recommended either to use this method for implementing Unit tests.

Finally, Axional Studio includes an Axional Test module, which allows implementing Unit tests. This module has been designed considering the main functionalities of testing applications and adapting them to the Axional Studio applications and developers. It implements the necessary forms and reports to implement and monitor Unit tests within the context of an Axional Studio application. In conclusion, it is the most recommended method for implementing Unit tests for Axional Studio applications.

2 Using Axional Test module

2.1 Installation

As Axional Test is a module included in Axional Studio, it is only required to assign the module dictionary database (wic_junit) to the test application. Once assigned, the Testing menu will be available in the application, with all the necessary options to implement Unit tests.

2.2 Test definition

In order to create and define or modify a Unit test, access Testing/Test Definition/Unit test. This catalogue test will enable you to access to all existing tests.

2.2.1 Unit test definition form

Unit identification

• Code: The test Code name is mandatory and it must be a unique identifier of the Test set (it contains one or more tests units). Use conventional syntax, with lowercase and underscore between separate words. As usual, it is preferable to give a meaningful name to the test.
• Lock: Use Lock option in order to avoid your test to be a result in a query from Tests executions or Test reports menu options. By doing so, this test will be performed only through this Unit Testing form and will be eliminated from Test reports.
• Tags: The test Tags (also mandatory) are the keywords that identify and classify the test content by means of a few words. These tags can be used to include or exclude test from Test executions in a fast and effective manner. This is the main reason why tags are of great importance, as a way to easily interact and manage the tests. Before creating your own tag, it is convenient to check if users are already using one on that subject.
• Description:

The test Description field allows a more detailed description without any pre-established format. And although it isn't mandatory, it is highly recommended.

Test Result

The test Result field will show the result of the last test execution by only three possible responses: error, failed and succeed. These responses depend on the test script and have been described in the Test Response section. When Test set holds multiple test units, the global state of the test instance corresponds to the most severe.

Succeed

Failed

Error

Test script

The programming code of the test must be inserted in the available test script area using JavaScript language. Consult Unit Test Code section if you require more information on the program. This section will help you to deeply understand how Axional Unit Testing works.

Execution Results

The Execution Result box includes detailed information about each of the test units that are contained in a Test set. In addition to general information about each of them (unit name, execution date, duration, ... ), it comprises separate results for each test unit and result counters since the last reset. Here we can find (when available) the Snapshot files (more information in the following link: Snapshoting ).

Reset and Execute

The Unit test form includes the result of the last execution of this test. Use the Reset button to delete execution results records, as well as information related to execution.

WARNING

When performing a Reset, both snapshot files will be erased too (when available).

To solely perform this test, press the Execute test button. For batch testing execution, access Test Execution menu of the application.

Control data and View

They cover general information and visualization data about the Test set.

2.3 Test execution

This option accesses a query form that allows to select desired Test. The application permits you to execute one or several tests simultaneously.

2.3.1 Single execution

There are two ways to perform a single execution:

• Executed via the Execute test button from the Unit test definition form.
• Select only one test through the query form options, usually via Code identification, since it is an unique value for each Test. Once selected, execute the test by pressing the "Execute" icon.

WARNING

The "execute" button will not show the result of the query. Instead, it will directly execute the selected tests resulting from the query form options. If you press the "execute" button without filling any field of the form, ALL TESTS will be executed (except those blocked).

2.3.2 Batch execution

In order to submit a group of tests for execution as a single unit, use the query options to select desired tests.

• Execute all tests: if you press the "execute" button without filling any field of the form, ALL TESTS will be executed (except those blocked).
• Tags selection: the including/excluding tag field is the most effective and useful manner to do better-informed choices. It is for this reason that the tag assignment must be careful and precise.

The example bellow shows a query where will execute all test_junit, assertrs and asserttext test tagged, except those with test_error tag.

Operation: insert the tag name in the including or excluding field. To add more than one tag, use the vertical bar or pike symbol "|" between the name of each tag. Remember that blocked tests will not be executed, even though they include the tag.

• Test execution results: as a result of a batch execution, regardless of the origin of the execution (simple, batch or automation), the process shows a list with the results.

This list includes the most relevant information: test code, test name (each execution of Unit test), result response (which include independent responses for each execution of Unit test) and a brief message stating the reason for the failure. It also includes the duration time of each test unit is expressed in milliseconds.

As figure shows, a quick filter has been included to visualize only the tests whose response is Error or Failed.

2.3.3 Automatization

Axional Studio provides Cron Tasks tool to parameterize program executions on a specific time or date.

2.4 Test reports

• Global status: in order to have a general overview in test results, use this option. Due to results of the tests are overwritten each time they are executed, the global test only shows the values and percentages of the last time that have been executed.
Global Status Report
• Unit test values: test results in absolute numbers.
• Unit test dashboard: percentage of the succed, error and failed test in a representatively colorful graphic.
• Unit test description: code, result, description and tags of every last test execution.
• Unit test report: this option shows a query form that allows you to select the desired test or test range. After pressing the "execute" query button, the application displays the query results. This result list has standard classifying and shorting options. When selecting a Test, the application accesses the Unit Tests Definition.
Unit Test Query Result