|
Blogs
IntroductionAccording to Martin Fowler Continuous Integration is: „a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible." A nice introduction to the topic is available his article here. In order to support continuous integration a number of software tools are available. In case you have never seen such a tool the Wikipedia article on Continuous Integration contains links to quite some of them. The main feature of these tools is to perform an automated build, execute all the available tests and create a report of the results either after each change to the code base or in predefined intervals. How the automated builds and test are executed depends heavily on the type of development projects and the used technologies. For software development in ABAP in the context of SAP several tools exist to enabling to ensure code quality. ABAP Unit and the SAP Code Inspector (SCI) are just two of them. This blog describes how one can setup a continuous integration server mainly based on SAP Code Inspector. Furthermore, a brief example is provided how "build results" can be exported and processed in order to integrate them with existing tools. Continuous Integration Server using SAP Code InspectorThe SAP Code Inspector (SCI) provides most of the functionality necessary to build a continuous integration server. It can be used to perform syntax checks, check for coding conventions (although I'm not a fan of strict coding conventions; anyone who still is should read "Clean Code: A Handbook of Agile Software Craftsmanship" by Robert C. Martin), calculate program metrics, execute performance checks and also execute ABAP Unit Test. Furthermore, SCI is extensible. One can easily write own tests and execute them together with the tests provided by SAP. Possible extensions could be the evaluation of the ABAP Unit test coverage or the execution of Selenium test scripts (cf. Automate Web Application Testing with Selenium for ABAP). The blog Automating ABAP Unit Test Runs with the Code Inspector by Stephen Pfeiffer provides a nice description on how to setup SCI to periodically execute ABAP Unit Tests. While automatically executing ABAP Unit Test periodically is a nice first step, SCI requires a user to manually check test results. As existing continuous integration servers usually either send emails to developers or create Web-based reports my goal was to setup something similar with SCI. After creating an inspection with the name ZC_LOY_EXT_SFW_INSPECTION and setting it up for periodic execution I took a look at the background jobs using SM37. Setting up an inspection for periodic execution simply creates a background job named something like CODEINSP_<InspectionName>_<InspectionVersion>. This background job consists of only one step executing the report RS_CI_PARALLEL. The report RS_CI_PARALLEL is part of the package S_CODE_INSPECTOR. The package contains several reports (cf. following figure) including RS_CI_EMAIL which, according to the description, can be used to send email notifications of SCI results.
Execution this report with the appropriate parameters (cf. following figure) sends an email containing all results of the inspection to the email address stored in user data.
The Email created by the delivered template looks similar to this: Errors occurred Hello Christian, during the run of inspection "ZC_LOY_EXT_SFW_INSPECTION" of codeinspector in *** at 30.12.09 there Syntax Check - ZC_CL_SFW_DEFAULTBALLOGGER Line 000004 : The exception ZCX_SFW_CUTOMIZINGEXP is ABAP Unit - ZC_CL_SFW_DEFAULTBALLOGGER Line 000226 : .... The next thing I did was creating a screen variant with these values. Using SM36 I added an additional step to the background job to execute RS_CI_EMAIL after each inspection run. To be able to do this I had to change the status of the exiting background job, add the step and release the background job again. Now each time an inspection is executed through the background job the latest inspection results are mailed to my. Automating Code Inspector ExecutionAs setting up the email notification for inspection results manually is rather cumbersome. Instead it would be nice to have a report that automatically performs the required steps for scheduling periodic SCI runs and the result notification via email. The following code snipplet does exactly this. TYPE-POOLS: abap. The code above assumes the existence of a check variant named MY_DEFAULT_CHECK_VAR. It creates an object set for the inspection that contains all objects in packages starting with the string ZC_LOY_EXT_SFW. Using the create object set and the check variant an inspection is create. Finally a background job executing the created inspection as well as the email notification is created. In this example the background job is setup to run every 5 minutes. So be careful not to flood your inbox ;) Integration with existing ToolsAnother thing, besides the email notification, that might be required is the integration of the inspection results into existing tools. For example, in a larger project the inspection results from SCI could need to be integrated with the reports generated by other tools. An integration of SCI with existing tools can also be achieved. As an example the following code exports the inspection results as XML using simple transformations: CONSTANTS: co_user_name LIKE sy-uname VALUE 'DRUMM', The exported file could now be used to integrate the inspection results with exisitng tools. As an example I created a ruby script that converts the exported file into a simple HTML report. The resulting HTML report looks something like this.
Christian Drumm works as a Project Manager at DSC Gmbh in Schriesheim.
| |||||||||||||||||||||||