quarta-feira, 6 de fevereiro de 2013

Unit Testing on ABAP

Hi folks,
Today i decided to publish a program that i made myself on my free times. I will explain the purpose and motivation behind it and i will share the code for everyone who want to try it.
 

Problem

In my previous company we had several periodic processes executed once a year at a specific month. Every year, we had new requirements, so we had to continually adapt our code to the new requirements. The painful part of it, was when we needed to test the code. Our customer worked with several countries with custom rules for each country and we need to test many scenarios. We needed to constantly repeat our huge test battery manually which normally could take several days to complete (more than the ones involved on the development itself).
 

eCATT

 
My first thought, was on SAP standard solution for testing. I made a "simple" proof of concept to test the capabilities around eCATT. I've remember that i've created a new system landscape container (something like this), the test script itself and the data container. Tried to explore the data container part which stores the data used on the test script. My knowledge on this tool was very low, however, i found out some problems on my proof of concept:
  • Load data from an external source
    • Embebbed data is organized in variants
    • I read somewhere that i can read the data from an excel file
  • Adapt the test script itself
    • Adapt multiple test scripts if signatures change is costy
  • eCATT is too complex for simple tasks

Motivation and Purpose

I was always fascinated with dynamic ABAP programming to push to the limits the capabilities arround ABAP code. So i started to design a tool that allowed me to both fulfill my problem around testing and enjoy programming with ABAP dynamic. My thought was reading a test script from a xml file with a simple structure easily modifiable.
Example of a test script:

 

  https://www.dropbox.com/s/uohgjk01yq47b8u/B1.xml
 



This test will call class YCL_PROJ_POSITION and method GET_POSITIONID with the parameters supplied in the example.




Functionalities

  • Generation
    • Generate an XML file for a function (or list of functions), methods, and programs
    • Allow the generation of examples on how to use
    • Allow the generation of commented types for each parameter of the function, program or method for easier introduction
 
  • XML Syntax
    • Allow the runtime substitution of variables for:
      • Dates
      • Times
  • Execution
    • Allow the generation of a PDF file at the end of the execution with the test results
    • Allow to ignore all break-points declared on the xml file.

Hands-on


Generate a file from a function


Generated file:
Execution:

Follows the link to the source-code:

https://www.dropbox.com/s/h0w9r1h2z60qeoz/Y_UNIT_TEST_XML.abap

I'm planning to create a video on how to use this. Feel free to provide your feedback if you try it