Automated Unit Testing of Adempiere Codes


Problem Statement

For product like Adempiere, which provides huge set of functionality off-the-shelf, the major challenge customer face is quality of the customized codes. Since the ERP is often considered as backbone of the company, obviously business expect high quality delivery to ensure that it always works correctly to ensure that their employee are focussed on the actual business work. While their immediate focus remain on the regression test automation, what they also need to know is that there are development tools, which can minimize their overall cost and improve the quality. That is where jUnit comes into play. Due to whatever reasons, jUnit has not been widely used in Adempiere world and we strongly believe that this makes life easier for the development team. The reusable unit test scripts allows developer to continue his focus on the current work, while jUnit ensure that he has not broken anything in the already completed work. We strongly believe that if ERP application architecture inherently supports building of test scripts and if these scripts can be prepared as part of development life cycle of the project, then it becomes additional advantage to produce high quality software.

Scope Of This Article

This article covers three topics
1. Steps to prepare Junit test cases for Adempiere
2. Changes we need to make to enable Adempiere for Junit testing of callouts
3. Steps to prepare Junit case for Adempiere callout

You can of course generalize the concepts talked over here to test other parts of your Adempiere code as well.

Technology

• Adempiere 370
• JUnit

For the business user, who may not have exact idea about jUnit, you can consider this as a test suite, which allows developer to define execution path through which the programming control shall flow by using appropriate input data. Also, it is assumed that in order to execute an already written test cases, the developer may need to make minimal amount of changes to be able to test reasonably good amount of codes. In general, The JUnit testing framework is standard unit testing API for Java
development.

Details

Let us see the steps we need to follow to implement Junit testcases. Adempiere has implicit support for Junit testcases. Adempiere code base has class AdempiereTestcase.java, which has all the required implementation support to prepare junit test cases

Step 1:
Create a new test class by extending AdempiereTestCase class

Step 2:
Overide setUp() method, to set the required data for Junit testcase

Step 3:
Create your own test method. The method name should start with “test” keyword. You can use assertEquals() or related assert methods to validate the output of test case.

Step 4:
Now run the testcase. However, before you run the testcase make sure Adempiere.properties is in right place as mentioned in AdempiereTestcase.java

Step 5:
Now let us make changes to support Junit testcases of callout. We need to make code changes in AdempiereTestcase.java class.

Step 5.1 Add a new private method setFieldValue() in AdempiereTestcase.java


It has three parameters,

  1. gridTab – object of gridTab on which we want set values
  2. calloutFieldName – Field on which we need to set the data
  3. value – Value that is set in the field

In this method, set the value and call the method to invoke callout

Step 5.2 Add new protected method testMyCallout() in AdempiereTestcase.java

It has four parameters,

  1. hashmap – Contains map of field names and its values
  2. windowName – Based on the window name, the window id will be derived.
  3. calloutTabIndex – Index of the tab in the given window on which we want conduct test
  4. ctx – Context

In this method, create gridtab object and call setFieldValue() method for each field, which intern executes the callout.

Step 6:
Create a new test class for callout by extending AdempiereTestcase class

Step 7:
Create your own test method and the method name should start with “test” keyword and it will call testMyCallout() method of AdempiereTestCase.java

Step 8:
Now run callout Junit testcase

Step 9
See the test report in eclipse. Green color indicates test case is executed successfully:

Summary

With minor change in Adempiere application, Adempiere supports automation of Unit testing for code changes including callout, which in turn helps development team in identifying the problems in early stages of development. In previous blog we have discussed automation of functional testing and if you combine that with the unit testing and its automation then this definitely ensure that you have better quality delivery.

Along with unit testing, unit test automation, solution test and regression test automation, at Walking Tree we also make use of continuous integration and code coverage measurement to ensure that our customers receive the top class quality. Walking Tree practices and encourage businesses to take advantage of Adempiere. In case you are looking for professional assistance, you can reach us by visiting our website.

Reference

http://www.adempiere.com/Adempiere_Junit_test
http://java.sun.com/developer/Books/javaprogramming/ant/ant_chap04.pdf
http://www.methodsandtools.com/tools/tools.php?junit

Tagged with: , , , ,
Posted in ADempiere

Leave a comment

We Have Moved Our Blog!

We have moved our blog to our company site. Check out https://walkingtree.tech/index.php/blog for all latest blogs.

Sencha Select Partner Sencha Training Partner
Xamarin Authorized Partner
Recent Publication