Anda di halaman 1dari 50

SAP CLOUD PLATFORM

ABAP ENVIRONMENT

ABAP

SAP HANA

CNA317 – Automated testing


within the ABAP programming model for SAP S/4HANA

PUBLIC
Speakers 2018

SAP TechEd Las Vegas Ingo Bräuninger


October 2–5, 2018

SAP TechEd Barcelona Ingo Bräuninger


October 23–25, 2018

SAP TechEd Bangalore Sunil Bandameedapalli


November 28–30, 2018

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 2


Take the session survey.
We want to hear from you!

Be sure to complete the session evaluation


on the SAP TechEd mobile app.

Download the app from


iPhone App Store or Google Play.

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 3


Disclaimer

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.

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 4


ABAP Strategy

CNA120
CNA317

Optimize Your Custom ABAP Code


for SAP HANA

CNA319
See the Big Picture of the ABAP
RESTful
Programming Model
CNA215

A Technical Deep Dive into the


ABAP RESTful
Programming Model
CNA216

1 hour lecture
Automated Testing with the ABAP
RESTful Programming Model
CNA317

Custom Code Adaptation for


SAP S/4HANA
CNA302

2 hours hands-on workshop

Build a List Report App with SAP


Fiori and ABAP Programming Model
CNA381

Build a Transactional SAP Fiori App


with the ABAP Programming Model
CNA379

1 hour codejam

Custom Code Adaptation for SAP


Automated Testing with the ABAP RESTful Programming Model

S/4HANA
CNA364
HOW TO MOVE YOUR ABAP SKILLS TO THE CLOUD AND SAP HANA

Build an SAP Fiori App with the


ABAP Programming Model
CNA654

Troubleshoot Your SAP Fiori App


with ABAP Development Tools for
Eclipse
CNA653
Agenda

Introduction to ABAP Unit

Why writing unit tests is a new skill

Testing OData Services

Managing various dependencies while writing tests in ABAP


CDS / OSQL Test Double Framework
ABAP Test Double Framework
ABAP Test Seams

Summary

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 6


In tro d u ctio n to
A B A P U n it
Automated unit testing

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

Find problems early in the development cycle


Help to avoid long debugging sessions
Make maintenance less painful with automated regression tests
Provide documentation
Enables faster software development lifecycle

GOAL
The goal of unit testing is to isolate each part of the program and show that the
individual parts work correctly

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 8


ABAP Unit

ABAP UNIT IS THE OFFICIAL xUNIT TESTING FRAMEWORK FOR ABAP

FEATURES OF ABAP UNIT

Provides an environment for execution of unit tests in isolation

Provides assertion-methods for testing expected results

Tightly integrated into the programming language ABAP

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

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 9


Phases of a unit test

Execute method Verify post- Cleanup


Establish pre-condition
under test condition (optional)

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 10


ABAP Unit
Test execution I

Executed before first setup class_setup()

Executed before each test method setup()

Test method execution test_method()

Executed after each test method teardown()

Executed after last teardown class_teardown()

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 11


ABAP Unit
Test execution II

EXECUTION OF A UNIT TEST CLASS

All test methods will be executed independent from each other

One instance of the test class per test method

Execution in undefined order

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 12


WHY WRITING UNIT TESTS
IS A NEW SKILL
Unit Testing

Here lies the challenge

Test case Code under test Dependent on


component

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 14


Unit Testing without isolation

Hard dependencies Function module


No isolation A bug here can
cause test failure

Test case Code under test Object

Wrong data here can


Database
cause test failure

Must exist, otherwise


Other entities testing is impossible

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 15


Unit Testing with isolation
Test doubles

Full control of
behaviour of the
Stub for
DOCs No dependencies function module
Full isolation

Test case Code under test Mock object


Test doubles
replace original
entities
Fake database

Dummy
Any test failure must be
caused by this code

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 16


HOW TO APPLY VARIOUS
ABAP UNIT APIS TO
TEST SAP FIORI APPS
Demo

Let’s have a look at the Fiori App example with high level components & UI

Are there any bugs?

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 18


eCATT test
support for
OData services

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 19


How Does OData Work at SAP?

CLIENT SYSTEM BUSINESS SERVER


SAP HANA / ABAP PLATFORM /
SAP JAVA STACK / EXTERNAL
SYSTEM

Provides OData service which


exposes business data

Calls OData service ODATA SERVICE


http(s) request / response
Entity container
Entity Set 1
CRUD operations

Entity Set 2
CRUD operations

Functions

A client system to call business server with OData service interface


© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 20
eCATT OData test architecture and eCATT OData assistant

OData test client on ABAP platform

eCATT test data container Test data definition


Layer with
test objects
ABAP unit test class eCATT test script Test logic

OData client access framework – ABAP


For each OData service entity set to be tested
Generate global service access class with CRUD methods Client access to
business data
Generate data types as local types in the class Layer with
provided by service
provide entity data in attributes and method returns service
provide access to service meta data access
objects

http(s) handling
request / response processing Technical service
error handling invoke
client side use of SAP Gateway

OData

System under test e.g SAP system using SAP Gateway


or any web server utilizing OData protocol

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 21


Demo

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

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 22


CDS test
double
framework

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 23


Demo

Let’s see how the usage of CDS entities impact your testing strategy

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 24


Challenges in test double creation for CDS dependencies

Code under test ABAP DBMS


is executed in DB

Dependency on
database artefacts
SQL view
Dependency on
database content Unit test

SQL view

TABLE

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 25


CDS test double framework
How it works

Development Object under test is CDS entity

INPUT CDS entity under test OUTPUT

Access Control

Dependent Dependent
CDS Entity 1 DDIC table 1

Dependent Dependent
CDS CDS

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 26


CDS test double framework
How it works

Identify the dependencies (DoCs) of CDS entity & isolate code under test from DoCs

INPUT CDS entity under test OUTPUT

Access Control

Dependent Dependent
CDS Entity 1 DDIC table 1

Dependent Dependent
CDS CDS

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 27


CDS test double framework
How it works
Create test doubles in the database for all the first level dependencies
Inject the test doubles into the clone of CDS entity under test
Insert test data into test doubles

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

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 28


Demo

Let’s write a test which tests the logic present in the CDS entity using the CDS test double
framework

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 29


ABAP CDS Test Double Framework
FEATURES OF ABAP CDS TEST DOUBLE FRAMEWORK

Available from SAP NetWeaver AS ABAP 7.51 SP00 onwards

Unit testing & Hierarchy testing of a CDS entity is possible

Testing CDS entity by enabling Access Control (DCL) using test doubles for role authorization objects

You can create test doubles for


DDIC tables, DDIC views, CDS views, CDS views with Parameters, External Views, Table Functions, CDS Special
Functions like CURRENCY_CONVERSION and UNIT_CONVERSION

Automatic code generation possibilities through


Wizard, for creating a new test class with test code

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.

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 30


Open SQL test double framework
FEATURES OF ABAP OPEN SQL TEST DOUBLE FRAMEWORK
Enables testing of the logic expressed in the Open SQL statements using the well -known ABAP Unit Test
Framework

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

Works seamlessly with all SAP supported databases

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)

Available with from SAP NetWeaver AS ABAP 7.52 SP00 onwards

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 31


ABAP
test double
framework

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 32


ABAP Test Double Framework

FEATURES OF ABAP TEST DOUBLE FRAMEWORK

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

Available with SAP BASIS release 740 SP9 and higher

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 33


Code snippet …

DATA: lo_currency_converter_double TYPE REF TO if_td_currency_converter.

“create test double object


lo_currency_converter_double ?= cl_abap_testdouble=>create( ‘if_td_currency_converter’ ).

“configuration for stubbing method ‘convert’:

“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’
).

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 34


Demo

Let’s write a test and replace the dependencies in the ABAP code by using the ABAP Test Double
Framework

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 35


ABAP
test seams
A test seam is a part of the code under test
which can be used to replace dependencies by
a test-friendly alternative

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 36


Untestable Code
METHOD get_countervalue.

DATA: converted_amount TYPE decfloat16, [...].

IF banknote->get_currency( ) = i_currency.
converted_amount = banknote->get_amount( ).
ELSE.

CALL FUNCTION 'CURRENCY_CONVERSION_CONVERT'


EXPORTING
i_source_currency = source_currency
i_target_currency = i_currency
i_source_amount = source_amount Call to DOC
Untestable code

IMPORTING
e_target_amount = converted_amount.

ENDIF.
ADD converted_amount TO r_countervalue.

ENDLOOP.

ENDMETHOD.

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 37


ABAP Test Seams – Injecting the test-friendly alternative value
METHOD get_countervalue.

CLASS ltc_wallet IMPLEMENTATION.


DATA: converted_amount TYPE decfloat16, [...].
Testable
code

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.

CALL FUNCTION 'CURRENCY_CONVERSION_CONVERT' wallet->add_banknote( eur_20 ).


Untestable

EXPORTING wallet->add_banknote( usd_10 ).


code

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.

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 38


ABAP test seams

FEATURES OF ABAP TEST SEAMS

Lightweight alternative to the ABAP Test Double Framework

Only works within a single compilation unit

Available with release 7.50 and higher

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 39


Demo

Let’s write a test for ABAP code and replace the test-unfriendly code by using the ABAP Test
Seams

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 40


SUMMARY
TESTABILITY - OVERVIEW

Smoke Tests CUT1


SECATT_ODATA Test Client OData Service
Integration Tests
Outside ABAP session
Protocol dependent
Inside ABAP session
Protocol independent
OData Test API CUT1
Scenario test Service Implementation
(based on ABAP Unit) PLANNED
FEATURE
ABAP TDF 2 (for creating a test
double for ABAP dependencies)
ABAP Class ABAP Test Seam (for replacing the
test-unfriendly code with user-defined
test code)

CUT1
CDS TDF 2 (for creating test doubles
Unit test ABAP Unit CDS for the data sources of the CDS Entity
under test)

OSQL TDF 2 (for creating test doubles


Persistency for the database dependencies in
ABAP Code)
using
1 Code Under Test 2 Test Double Framework

Test type Test API Unit Test isolation


(dependency management)
© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 42
Recommendation for test automation tools in SAP S/4 HANA

Test Type Execution Intensity Purpose Tools Examples

Manual & E2E scenario test of


System Tests complete stack
START/eCATT Order to Cash
automated

UI: START/eCATT,
Manual & Integration test of multiple Fiori App  backend
Integration Tests components Non-UI: eCATT oData Assistant, communication
automated eCATT

Test of single units & Frontend: {Qunit / OPA5 / mockserver}


Unit / Component oData service, ABAP API,
Tests automated components build out of Backend: ABAP Unit with ABAP TDF, Fiori App (isolated)
multiple units CDS TDF, OSQL TDF APIs

Find possible issues via Frontend: ESLint Disallow Unused


Static Code Checks automated static code scans Variables
Backend: ATC

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 43


ABAP Programming Model for SAP Fiori
Key takeaways

Where to safely invest now?

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!

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 44


The ABAP RESTful Programming Model
Cloud-first delivery approach in SAP Cloud Platform ABAP Environment

SERVICE SAP Fiori UI A2X


CONSUMPTION Consume OData UI services Consume OData A2X services

SERVICE BINDING
BUSINESS Bind the service to OData protocol
SERVICES
PROVISIONING SERVICE DEFINITION
Define scope to be exposed

BUSINESS OBJECTS QUERIES

Data modelling with CDS


DATA MODELLING &
BEHAVIOUR Behaviour definition Data modelling with CDS

Behaviour implementation
with ABAP

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC


CNA215 46
ABAP Platform Strategy – Further leveraging SAP HANA’s power

on premise on premise cloud

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

SAP NETWEAVER AS FOR ABAP PLATFORM


SAP S/4HANA ABAP PLATFORM CLOUD
ABAP 7.5x 2 AS A SERVICE

NO STANDALONE ABAP PLATFORM


3
INSTALLATION WHITELISTED APIs
CLASSIC ABA LAYER
NEW ABA LAYER NEW ABA LAYER NEW ABA LAYER
ANY DB & SAP HANA
SAP HANA ONLY SAP HANA ONLY SAP HANA ONLY

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

Access replays of:


 Keynotes
 SAP TechEd live interviews
 Selected lecture sessions

http://sapteched.com/online

Continue your SAP TechEd discussion after


the event within SAP Community:
 Read and reply to blog posts
 Ask your questions
 Join conversations

sap.com/community
See all SAP TechEd blog posts

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 48


Further information

Related SAP TechEd content journeys


CNA6 – How to Move Your ABAP Skills to the Cloud and SAP HANA
CNA4 – How to get to SAP S/4HANA

Related SAP TechEd sessions


CNA120 – ABAP Strategy
CNA215 – Set the Big Picture of the ABAP RESTful Programming Model
CNA216 – A Technical deep dive into the ABAP RESTful Programming Model
CNA317 – Automated Testing with the ABAP RESTful Programming Model
CNA319 – Optimize your Custom ABAP Code for SAP HANA
CNA379 – Build a transactional SAP Fiori App with the ABAP Programming Model
CNA654 – Build a SAP Fiori App with the ABAP Programming Model
CNA653 – Troubleshoot Your SAP Fiori App with ABAP Development Tools for Eclipse

Public SAP Web sites


ABAP Development Community: https://www.sap.com/community/topic/abap.html
SAP products: www.sap.com/products

SAP training and certification opportunities


www.sap.com/education
© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 49
Thanks for attending this session.

Feedback Contact for further topic inquiries

Please complete your session Carine Tchoutouo Djomo


Product Management of Technology Platform
evaluation for CNA317. carine.tchoutouo.djomo@sap.com

© 2018 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 50


Lectures only: Questions for TechEd Journey Badge “exam” pool* /
openSAP course SAP TechEd 2018 Recap**

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

Anda mungkin juga menyukai