Wednesday, March 14, 2012

Coverage Analysis for BPEL Activities

The concept of code coverage in software testing has been around since 1963 according to Wikipedia.  Basically the idea is to ensure that all source code statements have been executed during testing activities.  It occurred to me that source code coverage analysis could be done for BPEL processes in an Oracle Fusion Middleware environment using the data that is exposed by the Fusion Middleware Java API.

In a previous post, I blogged about how to use this API and I wanted to experiment more with it.  I built a small Java program that has this basic flow:
  1. Start the program by supplying the name of the SOA composite application along with the version number and partition which are both optional parameters.
  2. Use the Fusion Java API to retrieve the source code for any BPEL processes defined in the composite and parse the source code to retrieve the names of each  BPEL activity or step.
  3. Use the Fusion Java API to retrieve all instances where this composite has been executed and parse the instance audit trail to retrieve the names of each BPEL activity that has been executed.
  4. Compare these two lists to determine which activities have not yet been tested.  This is technically referred to as "Statement Coverage".
This program turned out to be fairly easy to create and I think will be quite useful in the future for unit testing.  You can download the complete source code here. 

Example

To test the coverage analysis, I created a simple SOA composite named CoverageTest1 with a BPEL process that has an IF activity as shown below.



BPEL source code:

    <if name="If1">
      <condition>1=1</condition>
      <assign name="Assign1">
        <copy>
          <from>"value1"</from>
          <to>$outputVariable.payload/client:result</to>
        </copy>
      </assign>
      <else>
        <assign name="Assign2">
          <copy>
            <from>"value2"</from>
            <to>$outputVariable.payload/client:result</to>
          </copy>
        </assign>
      </else>
    </if>

Note that the condition "1=1" will always return true, so that the ELSE activities will never be executed.

When I run the CoverageAnalyzer.java code from JDeveloper, I get the following response:

Step Assign2 has not been tested
Coverage for composite CoverageTest1 is not complete


1 comment:

  1. This is very interesting. I remember this was available out of the box in 10g platform. Looks like they drop the ball in 11g. I don;t see the link for the sample code. Could you please make it available or email me @ techypiyush@gmail.com

    ReplyDelete