This blog is part of the larger series on all new developer features in SAP HANA SPS 09:http://scn.sap.com/community/developer-center/hana/blog/2014/12/02/sap-hana-sps-09-new-developer-fea...
Unit testing and test driven development have increasingly become more popular in the industry in general and specifically within the SAP customer base. To meet this demand, SAP introduces both an Unit Test framework and a table/view Mock framework in SPS 09. Its important to note that this test framework is not automatically installed into SPS 09 however. The delivery unit for this framework is delivered as non-automatic content. This means its sitting on the file system of your HANA system and must be imported by an administrator. This is done because we assume customers will want these tools in their development systems probably not production systems. Therefore we allow you, the customer, to decide if you want the tools installed.
First of all there is one common tool for testing XS JavaScript and database content such as SQLScript and Views. It is all based upon the open source libraries detailed in the above section; several of which have been extended by custom assertions and test utilities specific to the HANA environment.
Test code and test data are developed beside your productive code in the same HANA instance as just another XSJSLIB development object. Test themselves are implemented in XSJS syntax in SAP HANA Studio or the Web-based Development Workbench.
The Unit tests can than be ran standalone in the Web browser via the URL:
/sap/hana/testtools/unit/jasminxs/TestRunner.xsjs?package=<package>
Where package = the repository package your test are located within.
These unit tests can also be ran directly from the SAP Web-based Development Workbench.
This has the advantage of displaying the code coverage directly within the editor of the SAP Web-based Development Workbench.
Code coverage can also be displayed in the standalone web tool as well:
By integrating the JavaScript line code coverage library BlanketJS into the XSUnit Test framework, it’s now possible to see, to which extent the JavaScript code is covered (percentage, line based) by the executed test run.
Note that all .xsjslib files which match pattern parameter (default “*Test”) are excluded per default.
Example 1: The coverage is measured for each imported .xsjslib file
http://<host>:<port>/sap/hana/testtools/unit/jasminexs/TestRunner.xsjs?package=sap.hana.testtools.mockstar&coverage=true
Example 2: The coverage is measured for each .xsjslib file located in the mockstar package
http://<host>:<port>/sap/hana/testtools/unit/jasminexs/TestRunner.xsjs?package=sap.hana.testtools&coverage=sap.hana.testtools.mockstar
Example 3: If you would like to exclude test helpers located in the tests package you can specify them via the “exclude” parameter
http://<host>:<port>/sap/hana/testtools/unit/jasminexs/TestRunner.xsjs?package=sap.hana.testtools&coverage=true&exclude=sap.hana.testtools.mockstar.tests
However the test tool can also be ran as a service call. This way if you like to execute the test on a regular basis or trigger by code changes you can use Jenkins as a continuous integration server. The unit tests are called remotely from Jenkins and the results are stored and displayed within Jenkins. This is a process that we use internally at SAP.
To write self-contained unit tests that are executable in any system, you have to test the HANA model in an isolated way.
An HANA View for example has typically dependencies to other HANA Views or to database tables. These dependencies pass data to the “View under test" and cannot be controlled and overwritten by the test. This means you need the possibility to mock dependencies of the “View under test".
The Mocking Framework, namely Mockstar helps you to test your models with specific test data that resides in dedicated test tables.
Therefore it creates you a copy of your origin view/procedure where the dependent views/tables are replaced by test tables.
These (temporary) tables can be prepared, controlled and filled by the test.
The advantages of mocking are:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
26 | |
15 | |
14 | |
14 | |
13 | |
8 | |
8 | |
7 | |
6 | |
5 |