Adempiere Code Coverage


Problem Statement

We all know that ERP is a HUGE system and it needs to be very well managed as this acts as a backbone of the business. Refer to our previous articles on Automated Unit Testing of Adempiere code and Automated Testing of Adempireto understand our focus and recommendation about the ways to ensure quality of your custom solution. While these processes ensure improved quality the business is still not assured about completeness of testing. They often have a question “Do we have enough test cases in our test suite to cover all the scenario?”. While the answer for coverage of “all scenario” will be discussed by combining several other things, it is always wiser to break your problems in smaller pieces. The modified question could be

  1. Do we have test case for all the commonly known / used functional scenario?
  2. Do I have test cases to cover all the existing codes?

The 1st point can be concluded with the required hard work of the functional expert, however, answer for 2nd point lies into code coverage to ensure that all the existing code is covered.  Considering the voulme of code in ERP, Code Coverage is becoming mandatory requirement for any ERP application to release product with high quality

 

About Code Coverage

A code coverage tool keeps track of which parts of your code get executed and which parts do not during a test suite execution. It is a measure used in software testing to analyse the degree to which the source code of a program has been tested (often using the automated test scripts). It often gives glimpse of Health of the product. It is one of the important factors in building bug free software. It informs what scenarios are not covered and what are covered.

There are number of coverage criteria that the tools can consider. However the tool (Cobertura) used by us covers following criteria

  • Package (module coverage)
  • Classes (Entity coverage)
  • Methods (for function coverage)
  • Branches (for condition coverage)
  • Lines (for statement coverage)

Following link shows a sample coverage report:

http://cobertura.sourceforge.net/sample/

Scope 

This article covers
1. Code Coverage of Adempiere application with Eclipse
2. Code coverage for manual/regression testing of Adempiere application

Tools / technology Used

 

Assumption

  • User knows how to use eclipse
  • Cobertura is installed in your eclipse

How do we do?

Steps to get code coverage using eclipse:

  1. Install Cobetura plugin from http://ecobertura.johoop.de/update/ site in you eclipse. Then Launch your eclipse and look at top Left Side on menu bar as shown in Image below, if you see the Icon which is enclosed in red rectangle that means Cobertura is installed in Eclipse 
  2. Now Open any of Junit Test case Java file ( Note: Provide link to Adempiere Junit testcase post) 
  3. Now Right Click on the File, you See Option with “Cover As”, then click on this option  Now that your test case is executed, you woukd like to verify the code Coverage for target Java Class
  4. Open the Target Java file, All the lines that are filled with ‘Light Green’ are covered as part of your test, Lines filled with ‘Light Pink’ are not covered You have seen Coverage at Class level, Now you may like see Code Coverage Results at Project Level, Module Level, Package Level
  5. Open Show View and Type “Coverage”, you see the following Image, Click on “Coverage Session View” 
  6. Open Show View and Type “Coverage”, you see the following Image, Click on “Coverage Session View”  (You can drill down to Package and to Class level by just clicking on corresponding entity)
    1. Lines means, number of Lines of Code Covered
    2. Total Means, Total Lines of Code
    3. Branches Means, Number of Conditions that are Covered
    4. Total Means, Total Number of Conditions
  7. If you don’t want to cover some of the files, then you can add exclusions for the Coverage as well. Select “Cover as” menu and select “Coverage Configurations” You can add exclusions, by Clicking on Filters Tab and “Add Exclude Filter” Button and Click on Apply Button. For example above image indicates that all the class which have “Test” in the file name will not be covered in Coverage Report

 

Steps to get code coverage for manual and regression testing

Adempiere application does not support code coverage inherently. To enable Adempiere application for coverage, you need to need to prepare one ant script and one adempiere process.

Step 1: Prepare a script to instrument Adempiere archive files like adempiere.jar for which we want to have coverage. This script should have two targets which are mandatory( Names are not important)

  • Instrument – To Instrument the archive files, use cobertura-insrument task
  • Report – To report code coverage, use cobertura-report task

Step 2: Update RUN_Server.sh and .bat file to call this script with instrument target, before application is launching

Step 3: Prepare a Adempiere Process to push the code coverage. This job needs to be scheduled to run periodically and it can be scheduled using default Adempiere scheduler mechanism

Step 4: Now bring up the Adempiere application

Step 5: Now login into application 

 

Step 6: Open business partner window and Create new business Partner (and Run few more tests as per your wish)

Step 7 :  Now run the ant script prepared in step 1 with report target, and see the coverage summary

Step 8 : Let us see the coverage for AbstractADWindowPanel Class in webui

 

Step 9 : You can see the code as well, light green means code is covered, pink means code line is not covered completely

Step 10 : Now see the coverage of base class i.e. MBPartner

 

Step 11: You can see the code for MBPatner as well

 

Note

You can get the code coverage, even when you run automated regression test cases irrespective of whether they are Junit test cases or html based selenium test cases.

Summary

In this article you saw how to identify code coverage through jUnit testing and regression testing. All you needed was an installation of one plug-in in eclipse to get the code coverage of Adempiere. Also, with some changes in Adempiere application code base, we can get the code coverage for manual and regression testing as well. This enables you to clearly identify the need for writing more test cases or remove dead codes from the solution. A 100% coverage ensure that when used in conjunction with the automated test suite, the regression testing becomes an automated task and as a QA lead all you need to do is to look at the report to ensure that none of the test cases fail and code coverage remains 100%.

Walking Tree ensures high quality delivery through the usage of QA tools like the one talked in this article. The QA practice used by Walking Tree is applicable across all its offering including codes consisting of PHP, ExtJS, Sencha Touch and other java based applications. In case you are looking for a professional assistance then do visit our website to get in touch with us.

 

Reference

  1. http://en.wikipedia.org/wiki/Code_coverage
  2. http://cobertura.sourceforge.net/
  3. http://www.ibm.com/developerworks/java/library/j-cobertura/
Tagged with: , , , , , , , ,
Posted in ADempiere

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

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
%d bloggers like this: