<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.infinite-erp.co.id/index.php?action=history&amp;feed=atom&amp;title=How_to_create_QUnit_testcases</id>
	<title>How to create QUnit testcases - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.infinite-erp.co.id/index.php?action=history&amp;feed=atom&amp;title=How_to_create_QUnit_testcases"/>
	<link rel="alternate" type="text/html" href="https://wiki.infinite-erp.co.id/index.php?title=How_to_create_QUnit_testcases&amp;action=history"/>
	<updated>2026-04-06T15:23:26Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.infinite-erp.co.id/index.php?title=How_to_create_QUnit_testcases&amp;diff=2795&amp;oldid=prev</id>
		<title>Wikiadmin: Created page with &quot;{{(!)| Starting to '''PR20Q1''' QUnit testing support will be completely removed and replaced by Jest. See How to create Jest test cases for m...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.infinite-erp.co.id/index.php?title=How_to_create_QUnit_testcases&amp;diff=2795&amp;oldid=prev"/>
		<updated>2021-12-16T05:01:58Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{(!)| Starting to &amp;#039;&amp;#039;&amp;#039;PR20Q1&amp;#039;&amp;#039;&amp;#039; QUnit testing support will be completely removed and replaced by Jest. See &lt;a href=&quot;/index.php?title=How_to_create_Jest_testcases&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;How to create Jest testcases (page does not exist)&quot;&gt;How to create Jest test cases&lt;/a&gt; for m...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{(!)| Starting to '''PR20Q1''' QUnit testing support will be completely removed and replaced by Jest. See [[How_to_create_Jest_testcases|How to create Jest test cases]] for more info}}&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
Openbravo provides [http://qunitjs.com/ QUnit] library as framework to write JavaScript unit test cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:QUnit-logo.png|center|100px]]&lt;br /&gt;
&lt;br /&gt;
=== The flow ===&lt;br /&gt;
&lt;br /&gt;
QUnit test cases defined within Openbravo are executed by opening &amp;lt;code&amp;gt;http(s)://your.server/openbravoContext/web/org.openbravo.client.kernel/ui-test-suite/&amp;lt;/code&amp;gt; URL. When accessing this URL this flow is executed:&lt;br /&gt;
&lt;br /&gt;
* QUnit library is loaded&lt;br /&gt;
* SmartClient is loaded&lt;br /&gt;
* An Openbravo session is created&lt;br /&gt;
* Openbravo application is loaded without being rendered&lt;br /&gt;
* Test resources are loaded and executed&lt;br /&gt;
&lt;br /&gt;
== Creating a new QUnit test case ==&lt;br /&gt;
&lt;br /&gt;
=== Declaring JavaScript test resources ===&lt;br /&gt;
&lt;br /&gt;
Openbravo QUnit test cases are written as JavaScript static resources, which needs to be declared in the [[Openbravo_3_Architecture#Component_Provider|ComponentProvider]] of the module that deploys them. They must be declared in the &amp;lt;code&amp;gt;getTestResources&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@ApplicationScoped&lt;br /&gt;
@ComponentProvider.Qualifier(ExampleComponentProvider.EXAMPLE_VIEW_COMPONENT_TYPE)&lt;br /&gt;
public class ExampleComponentProvider extends BaseComponentProvider {&lt;br /&gt;
    @Override&lt;br /&gt;
  public List&amp;lt;String&amp;gt; getTestResources() {&lt;br /&gt;
    final List&amp;lt;String&amp;gt; testResources = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
    testResources.add(&amp;quot;web/org.openbravo.client.application.examples/js/test/my-test.js&amp;quot;);&lt;br /&gt;
    return testResources;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{(!)|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.}}&lt;br /&gt;
&lt;br /&gt;
=== Implementing a test case ===&lt;br /&gt;
&lt;br /&gt;
Once the file with the test case is declared in the ComponentProvider it will be loaded when QUnit test cases are executed.&lt;br /&gt;
&lt;br /&gt;
Test cases look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
/*global QUnit */&lt;br /&gt;
&lt;br /&gt;
QUnit.module('org.openbravo.my.module');&lt;br /&gt;
&lt;br /&gt;
QUnit.test('Test 1', function () {&lt;br /&gt;
  QUnit.expect(2);&lt;br /&gt;
  QUnit.ok(isc, 'isc object is present');&lt;br /&gt;
  QUnit.ok(OB, 'OB object is present');&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
QUnit.test('Test 2', function () {&lt;br /&gt;
 // ...&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;[http://api.qunitjs.com/QUnit.module/ QUnit.module]&amp;lt;/code&amp;gt;: allows to group different related test cases. It is the equivalent of a [https://github.com/junit-team/junit/wiki/Aggregating-tests-in-suites test suite] in JUnit.&lt;br /&gt;
* &amp;lt;code&amp;gt;[http://api.qunitjs.com/QUnit.module/ QUnit.ok]&amp;lt;/code&amp;gt;: performs the assert, being satisfied whenever 1st parameter is truthy. There is a bunch of other methods to perform different types of [http://api.qunitjs.com/category/assert/ assertions].&lt;br /&gt;
&lt;br /&gt;
[http://qunitjs.com/cookbook/ Comprehensive documentation] can be found in the QUnit site.&lt;br /&gt;
&lt;br /&gt;
=== Executing ===&lt;br /&gt;
&lt;br /&gt;
All QUnit test cases are executed by just opening &amp;lt;code&amp;gt;http(s)://your.server/openbravoContext/web/org.openbravo.client.kernel/ui-test-suite/&amp;lt;/code&amp;gt; URL.&lt;br /&gt;
&lt;br /&gt;
[[Image:QUnit-execution.png|center|300px]]&lt;br /&gt;
&lt;br /&gt;
== Continuous Integration ==&lt;br /&gt;
&lt;br /&gt;
All Qunit test cases defined within Openbravo 3 distribution modules are automatically executed as part of the [[Continuous_Integration]].&lt;br /&gt;
&lt;br /&gt;
All of them appear in &amp;lt;code&amp;gt;int-gui &amp;gt; com.openbravo.test.integration.qunit.testscripts &amp;gt; QUnitExecution &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;/div&gt;</summary>
		<author><name>Wikiadmin</name></author>
		
	</entry>
</feed>