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.
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:
- Right click on OpenbravoTest project, click on Properties
- Select Java Build Path
- Click on Link Source button
- 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:
- Remote: the discounts are calculated using a remote test service that allows the deployment and execution of the discounts engine using node.
- Graal: the discounts engine is executed through GraalJS, using the Graal Discount Executor.
- Web Service: the discounts are calculated by invoking the Discounts Web Service. In this mode the discount scenario is recreated in database before executing the test, and deleted once the test finishes.
To select the execution type the following criteria is applied:
- If the remote test service is up, the discounts of the test will be calculated using the Remote mode.
- 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.
- If neither the service and tomcat are up, then the discounts are calculated using the Graal mode.
|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:
- It allows to debug the JS code
- The test are executed faster because the DAL initialization tasks are done just on the first test execution and not for every launched test.
To make use of this mode, the first step is to enable the test service.
Go to the test service folder
The first time running the test service it should be installed:
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.
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
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!
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:
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
Using the Discounts Web Service
To make use of the Discounts Web Service (WebService mode), the following steps should be performed:
- Ensure that the Remote Test Service is not up
- Start Tomcat
- Run the tests
How to create JUnit Test Cases
Client Side Development and API