Professional Documents
Culture Documents
Automated Testing
Automated Testing
ABAP ENVIRONMENT
ABAP
SAP HANA
PUBLIC
Speakers 2018
The information in this presentation is confidential and proprietary to SAP and may not be disclosed without the permission of SAP.
Except for your obligation to protect confidential information, this presentation is not subject to your license agreement or any other service
or subscription agreement with SAP. SAP has no obligation to pursue any course of business outlined in this presentation or any related
document, or to develop or release any functionality mentioned therein.
This presentation, or any related document and SAP's strategy and possible future developments, products and or platforms directions and
functionality are all subject to change and may be changed by SAP at any time for any reason without notice. The information in this
presentation is not a commitment, promise or legal obligation to deliver any material, code or functionality. This presentation is provided
without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a
particular purpose, or non-infringement. This presentation is for informational purposes and may not be incorporated into a contract. SAP
assumes no responsibility for errors or omissions in this presentation, except if such damages were caused by SAP’s intentional or gross
negligence.
All forward-looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from
expectations. Readers are cautioned not to place undue reliance on these forward-looking statements, which speak only as of their dates,
and they should not be relied upon in making purchasing decisions.
CNA120
CNA317
CNA319
See the Big Picture of the ABAP
RESTful
Programming Model
CNA215
1 hour lecture
Automated Testing with the ABAP
RESTful Programming Model
CNA317
1 hour codejam
S/4HANA
CNA364
HOW TO MOVE YOUR ABAP SKILLS TO THE CLOUD AND SAP HANA
Summary
DEFINITION
Unit testing is a software verification and validation method in which a unit (method,
function module) of an application will be tested to verify if it satisfies its functional
requirements
UNIT TESTS
GOAL
The goal of unit testing is to isolate each part of the program and show that the
individual parts work correctly
Production code and unit test code are bundled and transported together
Now enhanced to support testing of other development objects like ABAP Core Data Services
Full control of
behaviour of the
Stub for
DOCs No dependencies function module
Full isolation
Dummy
Any test failure must be
caused by this code
Let’s have a look at the Fiori App example with high level components & UI
Entity Set 2
CRUD operations
Functions
http(s) handling
request / response processing Technical service
error handling invoke
client side use of SAP Gateway
OData
Let’s write a OData test using SECATT_ODATA test client which detects the bug
Let’s fix the code and make the test run successful
Let’s see how the usage of CDS entities impact your testing strategy
Dependency on
database artefacts
SQL view
Dependency on
database content Unit test
SQL view
TABLE
Access Control
Dependent Dependent
CDS Entity 1 DDIC table 1
…
Dependent Dependent
CDS CDS
Identify the dependencies (DoCs) of CDS entity & isolate code under test from DoCs
Access Control
Dependent Dependent
CDS Entity 1 DDIC table 1
…
Dependent Dependent
CDS CDS
CLONE
INPUT of OUTPUT
CDS entity under test
Test Test
double double
for CDS Entity 1 for DDIC table 1
Dependent Dependent
CDS Entity 1 DDIC table 1
Let’s write a test which tests the logic present in the CDS entity using the CDS test double
framework
Testing CDS entity by enabling Access Control (DCL) using test doubles for role authorization objects
Quick Assist, for providing in-line context based code generation capabilities within the test class
Integration with eCATT Test Data Container (TDC) APIs making consumption of test code from TDC easier while
writing a test for a CDS entity.
Supports testing of all DML statements, not just SELECT statements, present in any of the ABAP development
objects
Supports double creation for many depended on components like DDIC Tables, DDIC Views, CDS Views, CDS
Views with Parameters, CDS Table Function and External Views
Replace database dependencies without the need to modify the actual code under test
Primary key constraints of the depended on artefacts are respected even for test doubles
Provides API to easily consume the large sets of reusable test data from eCATT TDC
Provides test isolation by creating test doubles in the database based on the actual database entities for each
test session. (Hint: Performance cost of database table creation should be positive)
The ABAP Test Double Framework has been designed to simplify and standardize the creation and
configuration of test double behavior
The framework currently supports the creation of test doubles for global interfaces
The outputs of a method call can be easily configured using the framework API. The values of returning,
exporting, changing parameters and also exceptions and events can be configured for each method call
Additionally, the framework provides functionality to verify interactions on the double object, e.g. the number of
times a method was called with specific input parameters
“step 1: set the desired returning value for the method call
cl_abap_testdouble=>configure_call( lo_currency_converter_double )->returning( 80 ).
“step 2: specifying which method should get stubbed
lo_currency_converter_double->convert(
EXPORTING
amount = 100
source_currency = ‘USD’
target_currency = ‘EUR’
).
Let’s write a test and replace the dependencies in the ABAP code by using the ABAP Test Double
Framework
IF banknote->get_currency( ) = i_currency.
converted_amount = banknote->get_amount( ).
ELSE.
IMPORTING
e_target_amount = converted_amount.
ENDIF.
ADD converted_amount TO r_countervalue.
ENDLOOP.
ENDMETHOD.
METHOD test_countervalue.
IF banknote->get_currency( ) = i_currency.
converted_amount = banknote->get_amount( ). Replace during TEST-INJECTION currency_conversion.
ELSE. test execution
converted_amount = 30.
TEST-SEAM currency_conversion.
END-TEST-INJECTION.
i_source_currency = source_currency
i_target_currency = i_currency ASSERT wallet->get_countervalue( 'USD' ) = 40.
i_source_amount = source_amount
ENDMETHOD.
IMPORTING
e_target_amount = converted_amount. ENDCLASS.
END-TEST-SEAM.
ENDIF.
ADD converted_amount TO r_countervalue.
Testable
ENDLOOP.
code
ENDMETHOD.
Let’s write a test for ABAP code and replace the test-unfriendly code by using the ABAP Test
Seams
CUT1
CDS TDF 2 (for creating test doubles
Unit test ABAP Unit CDS for the data sources of the CDS Entity
under test)
UI: START/eCATT,
Manual & Integration test of multiple Fiori App backend
Integration Tests components Non-UI: eCATT oData Assistant, communication
automated eCATT
The ABAP programming model for SAP Fiori is available and still evolving
Documentation available on the SAP Help Portal: ABAP Programming model for SAP Fiori
Use ABAP Core Data Services (CDS) – The next generation data modelling and access
Use CDS / BOPF integration and get familiar with BOPF concepts like determinations, validations and actions
Use OData exposure: @OData.publish:true or SEGW with Referenced Data Source for OData V2
Avoid DPC / MPC specific coding
Check out blog: Be prepared for the ABAP programming model in SAP S/4HANA
Avoid the use of OData V4 for your business scenario as for now
Go for an implementation based on the new ABAP programming model – It will provide OData V4 soon
If you must use OData V4 now then go for a code-based implementation but use CDS views for read access!
SERVICE BINDING
BUSINESS Bind the service to OData protocol
SERVICES
PROVISIONING SERVICE DEFINITION
Define scope to be exposed
Behaviour implementation
with ABAP
SAP Business Suite 1 SAP S/4HANA On Premise SAP S/4HANA Cloud SAP Cloud Platform ABAP
SAP NetWeaver hubs ABAP add-ons for SAP S/4HANA SAP Integrated Business Planning Environment
SAP NetWeaver add-ons Custom applications Extensions for SAP S/4HANA
Custom applications
MAINTENANCE
ONE COMMON ABAP PLATFORM INNOVATION CODELINE
CODELINE
1 2 3
ABAP 7.50 7.50, 7.51 and 7.52 starting with 1809 delivery
This is the current state of planning and may be changed by SAP at any time.
© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 47
SAP TechEd online / SAP Community
http://sapteched.com/online
sap.com/community
See all SAP TechEd blog posts
1 What are the phases of a unit test? 3 Which is the right unit test framework if your
Establish pre-condition, Execute method under development object under test is CDS entity?
test, Verify post-condition, Cleanup
ABAP CDS Test Double Framework
Lexical Analysis, Semantic Analysis, Intermediate
Code Generation, Code Optimization CUTE
Define, Ideate, Prototype, Test NUnit
Planing, Analysis, Design, Implementation ABAP CDS Profiling
2 What is meant by "Dependent on 4 What is the best way to introduce unit tests
Component"? for "legacy code"?
Dependent on Components are the dependencies ABAP Test Seams
that the Code Under Test (CUT) has
ABAP Business Rule Conditions
Dependent on components means to meet the
requirements of the unit test The Rhino Mocking Framework
To be in compliance with the requirements Implement the ABAP impact analysis
To be dependent on the magnetic field
© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 51