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

How to create QUnit testcases

Bulbgraph.png   Starting to PR20Q1 QUnit testing support will be completely removed and replaced by Jest. See How to create Jest test cases for more info

Contents

Overview

Openbravo provides QUnit library as framework to write JavaScript unit test cases.


QUnit-logo.png

The flow

QUnit test cases defined within Openbravo are executed by opening http(s)://your.server/openbravoContext/web/org.openbravo.client.kernel/ui-test-suite/ URL. When accessing this URL this flow is executed:

Creating a new QUnit test case

Declaring JavaScript test resources

Openbravo QUnit test cases are written as JavaScript static resources, which needs to be declared in the ComponentProvider of the module that deploys them. They must be declared in the getTestResources method.

 
@ApplicationScoped
@ComponentProvider.Qualifier(ExampleComponentProvider.EXAMPLE_VIEW_COMPONENT_TYPE)
public class ExampleComponentProvider extends BaseComponentProvider {
    @Override
  public List<String> getTestResources() {
    final List<String> testResources = new ArrayList<String>();
    testResources.add("web/org.openbravo.client.application.examples/js/test/my-test.js");
    return testResources;
  }
}
Bulbgraph.png   JavaScript test resources are only loaded when QUnit test cases are executed, they are not part of the common static resources that compose the application.

Implementing a test case

Once the file with the test case is declared in the ComponentProvider it will be loaded when QUnit test cases are executed.

Test cases look like:

 
/*global QUnit */
 
QUnit.module('org.openbravo.my.module');
 
QUnit.test('Test 1', function () {
  QUnit.expect(2);
  QUnit.ok(isc, 'isc object is present');
  QUnit.ok(OB, 'OB object is present');
});
 
QUnit.test('Test 2', function () {
 // ...
});

Comprehensive documentation can be found in the QUnit site.

Executing

All QUnit test cases are executed by just opening http(s)://your.server/openbravoContext/web/org.openbravo.client.kernel/ui-test-suite/ URL.

QUnit-execution.png

Continuous Integration

All Qunit test cases defined within Openbravo 3 distribution modules are automatically executed as part of the Continuous_Integration.

All of them appear in int-gui > com.openbravo.test.integration.qunit.testscripts > QUnitExecution

Retrieved from "http://wiki.openbravo.com/wiki/How_to_create_QUnit_testcases"

This page has been accessed 4,637 times. This page was last modified on 18 November 2019, at 12:49. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.