Professional Documents
Culture Documents
OpenSAP Wtc1 Week 1 All Slides
OpenSAP Wtc1 Week 1 All Slides
▪ Motivation
▪ ABAP unit
▪ Test-driven development
▪ Pair programming
▪ Test isolation
▪ Legacy code
▪ Continuous integration
Write Write
testable efficient
code and
effective
automated
tests
Advantages Integrated /
▪ Tests run in real environment System Test
Disadvantages
▪ Can be built only at end of development A B
▪ Complex setup of environment
▪ Long running tests
▪ High effort to analyze errors CATDD D X
▪ Fragile
▪ High maintenance
E F
CATDD D X
E F
Advantages
▪ Can be built during development
▪ Isolated from the environment
▪ Fast
A B
▪ Error analysis easy
▪ Stable Unit Test
▪ Low maintenance D
CATDD X
Disadvantage
▪ Tests run in simulated environment
E F
Decoupling
▪ Only decoupled product code enables you to write
your tests isolated from the environment
Refactoring
▪ “Refactoring is the process of changing a software
system in such a way that it does not alter the
external behavior of the code yet improves its
internal structure.”
Write Write
Martin Fowler [2]
testable efficient
Clean Code code and
effective
▪ “Clean code always looks like it was written by automated
someone who cares.” tests
Robert C. Martin [3]
manual
open@sap.com
© 2017 SAP SE or an SAP affiliate company. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
The information contained herein may be changed without prior notice. Some software products marketed by SAP SE and its distributors contain proprietary software components
of other software vendors. National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated
companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company products and services are those that are
set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or release
any functionality mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future developments, products,
and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The
information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. 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,
and they should not be relied upon in making purchasing decisions.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company)
in Germany and other countries. All other product and service names mentioned are the trademarks of their respective companies.
See http://global.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
Week 1: Introduction to ABAP Unit Testing
Unit 2: Introduction to ABAP Unit
Introduction to ABAP Unit
Money machine
PUBLIC SECTION.
METHODS get_amount_in_coins
IMPORTING i_amount TYPE i
RETURNING VALUE(r_value) TYPE i.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
METHOD get_amount_in_coins.
r_value = COND #( WHEN i_amount <= 0
THEN -1
ELSE i_amount MOD 5 ).
ENDMETHOD.
ENDCLASS.
METHOD get_amount_in_coins.
r_value = COND #( WHEN i_amount <= 0
THEN -1
ELSE i_amount MOD 5 ).
ENDMETHOD.
ENDCLASS.
ENDMETHOD.
CLASS cl_money_machine IMPLEMENTATION.
ENDCLASS.
METHOD get_amount_in_coins.
r_value = COND #( WHEN i_amount <= 0
THEN -1
ELSE i_amount MOD 5 ).
ENDMETHOD.
ENDCLASS.
PROTECTED SECTION.
PRIVATE SECTION. CLASS ltc_get_amount_in_coins IMPLEMENTATION.
ENDCLASS.
METHOD amount_1_coin_1.
"given
CLASS cl_money_machine IMPLEMENTATION.
"when
METHOD get_amount_in_coins.
r_value = COND #( WHEN i_amount <= 0 "then
THEN -1
ELSE i_amount MOD 5 ). ENDMETHOD.
ENDMETHOD.
ENDCLASS.
ENDCLASS.
PROTECTED SECTION.
PRIVATE SECTION. CLASS ltc_get_amount_in_coins IMPLEMENTATION.
ENDCLASS.
METHOD amount_1_coin_1.
"given
CLASS cl_money_machine IMPLEMENTATION. DATA(cut) = NEW cl_money_machine( ).
ENDCLASS.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 8
Introduction to ABAP Unit
Second test method
METHOD amount_2_coin_2.
"given
DATA(cut) = NEW cl_money_machine( ).
"when
DATA(coin_amount) = cut->get_amount_in_coins( 2 ).
"then
cl_abap_unit_assert=>assert_equals( act = coin_amount
exp = 2 ).
ENDMETHOD.
ENDCLASS.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 9
Introduction to ABAP Unit
Unit test framework – Special methods
▪ CLASS_SETUP
static method, called once before the first SETUP of the test class
▪ SETUP
instance method, called before each test method
▪ TEARDOWN
instance method, called after each test method
▪ CLASS_TEARDOWN
static method, called once after the last TEARDOWN of the test class
Common properties
▪ optional – only define them if you need them
▪ private
▪ have no parameters
METHOD amount_2_coin_2.
"given
DATA(cut) = NEW cl_money_machine( ).
"when
DATA(coin_amount) = cut->get_amount_in_coins( 2 ).
"then
cl_abap_unit_assert=>assert_equals( act = coin_amount
exp = 2 ).
ENDMETHOD.
ENDCLASS.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 11
Introduction to ABAP Unit
Refactor test methods
open@sap.com
© 2017 SAP SE or an SAP affiliate company. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
The information contained herein may be changed without prior notice. Some software products marketed by SAP SE and its distributors contain proprietary software components
of other software vendors. National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated
companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company products and services are those that are
set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or release
any functionality mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future developments, products,
and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The
information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. 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,
and they should not be relied upon in making purchasing decisions.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company)
in Germany and other countries. All other product and service names mentioned are the trademarks of their respective companies.
See http://global.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
Week 1: Introduction to ABAP Unit Testing
Unit 3: Demo of ABAP Unit Testing in Roman
Numerals
Demo of ABAP Unit Testing in Roman Numerals
Unit Test Exercise
Your task is to write unit tests for the converter and find the bug
hidden in the code with your tests – and then fix it.
Trainer Demo:
▪ Write first three tests
▪ Show ABAP Development Tools
Perspectives
Layout
Shortcuts
• Quick fix (Ctrl-1)
• Execute unit test (Shift-Ctrl-F10)
open@sap.com
© 2017 SAP SE or an SAP affiliate company. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
The information contained herein may be changed without prior notice. Some software products marketed by SAP SE and its distributors contain proprietary software components
of other software vendors. National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated
companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company products and services are those that are
set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or release
any functionality mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future developments, products,
and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The
information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. 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,
and they should not be relied upon in making purchasing decisions.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company)
in Germany and other countries. All other product and service names mentioned are the trademarks of their respective companies.
See http://global.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
Week 1: Introduction to Unit Testing
Unit 4: Exercise – ABAP Unit Testing in Roman
Numerals
Exercise – ABAP Unit Testing in Roman Numerals
Where to find the code
Your task is to write unit tests for the converter and find the bug
hidden in the code with your tests – and then fix it.
open@sap.com
© 2017 SAP SE or an SAP affiliate company. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
The information contained herein may be changed without prior notice. Some software products marketed by SAP SE and its distributors contain proprietary software components
of other software vendors. National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated
companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company products and services are those that are
set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or release
any functionality mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future developments, products,
and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The
information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. 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,
and they should not be relied upon in making purchasing decisions.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company)
in Germany and other countries. All other product and service names mentioned are the trademarks of their respective companies.
See http://global.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
Week 1: Introduction to ABAP Unit Testing
Unit 5: Review of Sample Solution
Review of Sample Solution
ABAP Unit Testing in Roman Numerals
open@sap.com
© 2017 SAP SE or an SAP affiliate company. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
The information contained herein may be changed without prior notice. Some software products marketed by SAP SE and its distributors contain proprietary software components
of other software vendors. National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated
companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company products and services are those that are
set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or release
any functionality mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future developments, products,
and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The
information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. 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,
and they should not be relied upon in making purchasing decisions.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company)
in Germany and other countries. All other product and service names mentioned are the trademarks of their respective companies.
See http://global.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
Week 1: Introduction to Unit Testing
Unit 6: Unit Test Design, Tips, and Benefits
Unit Test Design, Tips, and Benefits
What cases to cover?
Consider for your test cases… For large numbers of independent but interacting
▪ Positive cases – correct values variables, consider Combinatorial Test Design
▪ Negative cases – incorrect values
▪ Boundary values and their proximity
▪ Combinations of input values
open@sap.com
© 2017 SAP SE or an SAP affiliate company. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
The information contained herein may be changed without prior notice. Some software products marketed by SAP SE and its distributors contain proprietary software components
of other software vendors. National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated
companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company products and services are those that are
set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or release
any functionality mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future developments, products,
and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The
information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. 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,
and they should not be relied upon in making purchasing decisions.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company)
in Germany and other countries. All other product and service names mentioned are the trademarks of their respective companies.
See http://global.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.