View source | Discuss this page | Page history | Printable version   

How to run Discounts Test Cases



This how-to will focus on showing how to run the discounts test cases with the different execution modes that are available.

Module distribution

Currently the discounts test cases are separated into different modules in src-test folder:

All of these tests are grouped in a main test suite that can be used to execute them together:

Preparing the development environment

First of all, ensure that the JS Executor module is installed in your environment, together with the modules that contain the test cases.

Then you need to import src-test components of the Openbravo ERP as explained here.

Finally you will need to also link the src-test folder that contains the discounts test to the OpenbravoTest project:

  1. Right click on OpenbravoTest project, click on Properties
  2. Select Java Build Path
  3. Click on Link Source button
  4. Browse the src-test folder of the module that contains the test cases and click Finish

Running the test cases

The discounts test cases support three different execution types that define how the discounts of the test are calculated:

To select the execution type the following criteria is applied:

  1. If the remote test service is up, the discounts of the test will be calculated using the Remote mode.
  2. If the remote test service is not up but tomcat server is up, the discounts of the test will be calculated using the Web Service mode.
  3. If neither the service and tomcat are up, then the discounts are calculated using the Graal mode.
Bulbgraph.png   After finish the development of a new test case it is recommended to ensure that it works fine in all the three execution modes.

Using the Remote Test Service

This Remote mode is the recommended mode when developing, because:

To make use of this mode, the first step is to enable the test service.

Go to the test service folder

cd <source_path>/modules/org.openbravo.service.jsexecutor/src-test/js/

The first time running the test service it should be installed:

npm ci

And then, to start the service:

npm run-script test

Now if we run the test cases, the discount engine code will be deployed (just on the first test execution) into the service and the discount calculation will be done through the service.

Debug Mode

It possible to run the service in debug mode which allows to debug the deployed JS sources (the discounts engine and rules) using the browser's developers tools.

To run the service in debug mode:

npm run-script debug

And then open in Chrome: chrome://inspect

Chrome Inspect

Select the test-service.js target, and then the developers tools will be opened and ready to debug the sources deployed on the service.

Run the tests and you can debug the code!

Hot Deployment

The service supports hot deployment of the sources inside WebContent/web. To enable it is necessary to have some module in in development status and run the JSTestDeployer. This is a java class that should be launched as a regular test case. Once the JSTestDeployer is running all the changes done in the files inside WebContent/web will be automatically deployed into the service without the need of restarting it.

Having the JSTestDeployer running, it is also possible to force a redeploy by executing this command inside WebContent/web folder:

touch deploy

Coverage Mode

It is also possible to run the service in coverage mode. In this mode a code coverage report can be generated after running the tests.

To run the service in coverage mode:

npm run-script coverage

Then execute the tests, stop the service and run

node_modules/.bin/nyc report --reporter=html

An HTML will be generated at

Code Coverage Report

Using the Discounts Web Service

To make use of the Discounts Web Service (WebService mode), the following steps should be performed:

  1. Ensure that the Remote Test Service is not up
  2. Start Tomcat
  3. Run the tests

Related Links

How to create JUnit Test Cases

Client Side Development and API

Retrieved from ""

This page has been accessed 3,182 times. This page was last modified on 5 September 2022, at 10:09. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.