SlideShare a Scribd company logo
1 of 14
Download to read offline
© Kaufland 2016 |
ABAP CODERETREAT WEINSBERG
Unit Testing
KIS, Weinsberg, 23.07.2016
ABAP CodeRetreat Weinsberg121.07.2016
© Kaufland 2016 |
WHO WE ARE
KAUFLAND
We are more than just a successful international trading company:
We are a company where many colleagues become a team, jobs
are safe workplaces and real satisfaction
Diversity and stability
We offer a wide range of jobs with many different entry-levels and
career opportunities. Our company is continuously growing, that
makes us self-confident
Openness and friendly cooperation
We support a cooperation based on friendliness and mutual trust
ABAP CodeRetreat Weinsberg221.07.2016
© Kaufland 2016 |
WHERE WE ARE
KAUFLAND
Expansive growth, economic size
• We are successfully expanding in Germany, Poland, Czech
Republic, Slovakia, Croatia, Romania and Bulgaria
• Over 150,500 employees form our strong Kaufland team in
Europe
International cooperation and prospects
• We offer an international work environment
• We provide a wide variety of tasks in collaboration with our
international colleagues
• According to the area of deployment you will have the
opportunity to collect experience abroad, in one of our
European locations
ABAP CodeRetreat Weinsberg321.07.2016
© Kaufland 2016 | ABAP CodeRetreat Weinsberg4
KAUFLAND INFORMATION SYSTEMS
We are the IT service provider for Kaufland. Ensuring high
business performance and carrying data streams on the right track
is our daily responsibility
Keep IT simple and safe
Our objectives are to comprehensively advice our business
departments in designing their business processes and to
implement software solutions
OUR IT IN FIGURES
21.07.2016
220
SAP
Systems
40
SAP
Developers
25k Z Reports
© Kaufland 2016 |
UNIT TESTING
ABAP CodeRetreat Weinsberg521.07.2016
Unit Testing
Integration Testing
System Testing
Acceptance Testing
© Kaufland 2016 | ABAP CodeRetreat Weinsberg6
• Set up an initial state
• Confront the method under test with test values
• Compare actual value with expected test value
• Implemented in form of test methods
• Test methods are hosted in a test class
• Test classes are local classes to the program object under test
• Use global test classes only to host reusable logic for tests
• Comparisons are done with class CL_ABAP_UNIT_ASSERT
UNIT TESTS ABAP UNIT TESTS
CREATING ABAP UNIT TESTS
UNIT TESTING
21.07.2016
© Kaufland 2016 |
• Test classes are local classes defined with the FOR TESTING addition
• Test methods are (private) parameterless instance methods, also declared with the FOR TESTING
addition
• Use Fixtures to ensure particular starting conditions
• [class] setup and [class] teardown
TEST CLASSES AND TEST METHODS
ABAP CodeRetreat Weinsberg7
UNIT TESTING
21.07.2016
setup( ).
teardown( ).
my_first_test_method( ).
© Kaufland 2016 |
EXAMPLE
ABAP CodeRetreat Weinsberg8
UNIT TESTING
21.07.2016
© Kaufland 2016 |
• Testing starts already during the design of your application
• The following slides show some pitfalls you should keep in mind
• All coding samples are more or less pseudo-code in ABAP style
PREPARATION
ABAP CodeRetreat Weinsberg9
UNIT TESTING
21.07.2016
© Kaufland 2016 | ABAP CodeRetreat Weinsberg10
PITFALL #1
CLASS car.
PRIVATE SECTION.
DATA g_fuel TYPE i.
PUBLIC SECTION.
set_fuel IMPORTING i_fuel TYPE i.
has_fuel RETURNING r_has_fuel TYPE xfeld.
ENDCLASS.
CLASS testcar FOR TESTING.
PRIVATE SECTION.
DATA g_testobject TYPE REF TO car.
METHOD class_setup.
g_testobject = NEW #( ).
METHOD test_fuel.
g_testobject->set_fuel( 30 ).
METHOD test_has_fuel.
DATA(has_fuel) = g_test_object->has_fuel( ).
ENDCLASS.
UNIT TESTING
21.07.2016
• Test cases guarantee no order!
• When method test_has_fuel() is called
we do not know in which state the test-
object already is!
• Take care to initialize your test-object before
each testcase so that you know the current
state! (e.g. use setup() instead of
class_setup())
Each testmethod has to return the same
result each time it's called otherwise we cannot
test it.
© Kaufland 2016 | ABAP CodeRetreat Weinsberg11
PITFALL #2
CLASS order.
DATA g_order_number TYPE i.
METHOD get_positions.
" load data
SELECT * FROM mseg
WHERE mblnr = g_order_number.
" prepare data
" do something else
" return result.
ENDCLASS.
UNIT TESTING
21.07.2016
• We do not know what is currently in the
database!
• We do not know which data will be
prepared!
• We cannot assume what data will be
returned!
Do not load information from sources that
cannot be controlled during testing. Load
data before instantiating the order object.
This will enable us to write a testmethod for
the data preparation.
Alternative solution: use a database-
handler-class and pass it as a parameter.
During testing you can use a mock of the
database-handler that returns fix results.
© Kaufland 2016 | ABAP CodeRetreat Weinsberg12
PITFALL #3
CLASS store.
METHOD is_opened.
CALL FUNCTION 'DATE_COMPUTE_DAY'
EXPORTING
date = sy-datum
IMPORTING
day = day.
IF day <> 7.
r_is_opened = abap_true.
ENDIF.
ENDCLASS.
UNIT TESTING
21.07.2016
• If we expect the store to be closed the
testmethod will only succeed on sundays
• Testmethods expect a hard-coded result. Not
possible in this case!
Don't use system (or other) variables that you
cannot control. Better give the date as parameter.
So your testmethod can call
testobject->is_opened( '20160505' ).
© Kaufland 2016 | ABAP CodeRetreat Weinsberg13
UNIT TESTING
21.07.2016
POSSIBLE ARCHITECTURE
Database
Database
provider
Business
object
Data Access
Object (DAO)
Database layer Business layerAccess layer
© Kaufland 2016 |
• Sample Reports in package: SABP_UNIT_SAMPLE
• Executing Tests: Ctrl + Shift + F10
• Verification of test expectations: CL_ABAP_UNIT_ASSERT
• Test classes and methods are defined / declared with the FOR TESTING addition
• Considerations on how to write testable code must be included in the design avoid the pitfalls
HOW TO GET STARTED / KEY TAKEAWAYS
ABAP CodeRetreat Weinsberg14
UNIT TESTING
21.07.2016

More Related Content

What's hot

Final Automation Testing
Final Automation TestingFinal Automation Testing
Final Automation Testing
priya_trivedi
 

What's hot (19)

Building reliable applications with React, C#, and Azure
Building reliable applications with React, C#, and AzureBuilding reliable applications with React, C#, and Azure
Building reliable applications with React, C#, and Azure
 
Building large and scalable mission critical applications with React
Building large and scalable mission critical applications with ReactBuilding large and scalable mission critical applications with React
Building large and scalable mission critical applications with React
 
Tests for Every Branch Using CircleCI and Sauce Labs to Continuously Test CS ...
Tests for Every Branch Using CircleCI and Sauce Labs to Continuously Test CS ...Tests for Every Branch Using CircleCI and Sauce Labs to Continuously Test CS ...
Tests for Every Branch Using CircleCI and Sauce Labs to Continuously Test CS ...
 
Test Armada Sauce Labs
Test Armada Sauce LabsTest Armada Sauce Labs
Test Armada Sauce Labs
 
Introduction to Gauge
Introduction to GaugeIntroduction to Gauge
Introduction to Gauge
 
I am hooked on React
I am hooked on ReactI am hooked on React
I am hooked on React
 
Qa workshop
Qa workshopQa workshop
Qa workshop
 
Building a culture of quality at scale
Building a culture of quality at scaleBuilding a culture of quality at scale
Building a culture of quality at scale
 
Final Automation Testing
Final Automation TestingFinal Automation Testing
Final Automation Testing
 
Execute Automation Testing in 3 Steps
Execute Automation Testing in 3 StepsExecute Automation Testing in 3 Steps
Execute Automation Testing in 3 Steps
 
Testing OSGi-based Applications with DA-Testing
Testing OSGi-based Applications with DA-TestingTesting OSGi-based Applications with DA-Testing
Testing OSGi-based Applications with DA-Testing
 
Feature toggles
Feature togglesFeature toggles
Feature toggles
 
Test & Dynamics CRM - extremeCRM Berlin 2012
Test & Dynamics CRM - extremeCRM Berlin 2012Test & Dynamics CRM - extremeCRM Berlin 2012
Test & Dynamics CRM - extremeCRM Berlin 2012
 
Automation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDDAutomation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDD
 
ATAGTR2017 Keeping pace with Product Evolution: UI Automation Framework Guide...
ATAGTR2017 Keeping pace with Product Evolution: UI Automation Framework Guide...ATAGTR2017 Keeping pace with Product Evolution: UI Automation Framework Guide...
ATAGTR2017 Keeping pace with Product Evolution: UI Automation Framework Guide...
 
Qa process 2012
Qa process 2012Qa process 2012
Qa process 2012
 
Automation With A Tool Demo
Automation With A Tool DemoAutomation With A Tool Demo
Automation With A Tool Demo
 
Episode 3 – Classes, Inheritance, Abstract Class, and Interfaces
Episode 3 – Classes, Inheritance, Abstract Class, and InterfacesEpisode 3 – Classes, Inheritance, Abstract Class, and Interfaces
Episode 3 – Classes, Inheritance, Abstract Class, and Interfaces
 
Web tech: lecture 5
Web tech: lecture 5Web tech: lecture 5
Web tech: lecture 5
 

Viewers also liked

SAP Inside Track Lima 09 - Keynote
SAP Inside Track Lima 09 - KeynoteSAP Inside Track Lima 09 - Keynote
SAP Inside Track Lima 09 - Keynote
Alvaro Tejada
 
SAP Inside Track Lima 09 - Ruby y SAP
SAP Inside Track Lima 09 - Ruby y SAPSAP Inside Track Lima 09 - Ruby y SAP
SAP Inside Track Lima 09 - Ruby y SAP
Alvaro Tejada
 

Viewers also liked (12)

ABAPCodeRetreat 23.7.2016 - TDD
ABAPCodeRetreat 23.7.2016 - TDDABAPCodeRetreat 23.7.2016 - TDD
ABAPCodeRetreat 23.7.2016 - TDD
 
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAPABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
 
ABAPCodeRetreat - ABAP PUSH CHANNELS and SAP FIORI
ABAPCodeRetreat -   ABAP PUSH CHANNELS and SAP FIORIABAPCodeRetreat -   ABAP PUSH CHANNELS and SAP FIORI
ABAPCodeRetreat - ABAP PUSH CHANNELS and SAP FIORI
 
TDD in the ABAP world - sitNL 2013 edition
TDD in the ABAP world - sitNL 2013 editionTDD in the ABAP world - sitNL 2013 edition
TDD in the ABAP world - sitNL 2013 edition
 
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
 
SAP Inside Track Lima 09 - Keynote
SAP Inside Track Lima 09 - KeynoteSAP Inside Track Lima 09 - Keynote
SAP Inside Track Lima 09 - Keynote
 
Happy sap hana friends
Happy sap hana friendsHappy sap hana friends
Happy sap hana friends
 
SAP Inside Track Lima 09 - Ruby y SAP
SAP Inside Track Lima 09 - Ruby y SAPSAP Inside Track Lima 09 - Ruby y SAP
SAP Inside Track Lima 09 - Ruby y SAP
 
SmallWorlds - BoF Las Vegas TechEd 2008
SmallWorlds - BoF Las Vegas TechEd 2008SmallWorlds - BoF Las Vegas TechEd 2008
SmallWorlds - BoF Las Vegas TechEd 2008
 
ABAP Unit and TDD
ABAP Unit and TDDABAP Unit and TDD
ABAP Unit and TDD
 
The best debugging tool - your brain
The best debugging tool - your brainThe best debugging tool - your brain
The best debugging tool - your brain
 
1H2007 Results Full
1H2007 Results Full1H2007 Results Full
1H2007 Results Full
 

Similar to ABAPCodeRetreat 23.7.2016 - Unit Testing

MEASURE project : Measuring Software Engineering, OW2con'18, June 7-8, 2018, ...
MEASURE project : Measuring Software Engineering, OW2con'18, June 7-8, 2018, ...MEASURE project : Measuring Software Engineering, OW2con'18, June 7-8, 2018, ...
MEASURE project : Measuring Software Engineering, OW2con'18, June 7-8, 2018, ...
OW2
 
Automating sap testing with qtp10 & qc10
Automating sap testing with qtp10 & qc10Automating sap testing with qtp10 & qc10
Automating sap testing with qtp10 & qc10
Patrick Sun
 
CV_AUTOMATION_TEST_ENGINEER
CV_AUTOMATION_TEST_ENGINEERCV_AUTOMATION_TEST_ENGINEER
CV_AUTOMATION_TEST_ENGINEER
PERLA RAVI THEJA
 

Similar to ABAPCodeRetreat 23.7.2016 - Unit Testing (20)

Expert sizing &amp; methods of sizing validation
Expert sizing &amp; methods of sizing validationExpert sizing &amp; methods of sizing validation
Expert sizing &amp; methods of sizing validation
 
CV Gabor Vigh
CV Gabor VighCV Gabor Vigh
CV Gabor Vigh
 
DOES16 London - Darren Hague - SAP’s DevOps Journey: From Building an App to ...
DOES16 London - Darren Hague - SAP’s DevOps Journey: From Building an App to ...DOES16 London - Darren Hague - SAP’s DevOps Journey: From Building an App to ...
DOES16 London - Darren Hague - SAP’s DevOps Journey: From Building an App to ...
 
Perf tuning with-multitenant
Perf tuning with-multitenantPerf tuning with-multitenant
Perf tuning with-multitenant
 
MEASURE project : Measuring Software Engineering, OW2con'18, June 7-8, 2018, ...
MEASURE project : Measuring Software Engineering, OW2con'18, June 7-8, 2018, ...MEASURE project : Measuring Software Engineering, OW2con'18, June 7-8, 2018, ...
MEASURE project : Measuring Software Engineering, OW2con'18, June 7-8, 2018, ...
 
Code vigil
Code vigilCode vigil
Code vigil
 
Measure project ow2-2018
Measure project   ow2-2018Measure project   ow2-2018
Measure project ow2-2018
 
10 ошибок в работе с аналитикой / Вера Карпова (devtodev)
10 ошибок в работе с аналитикой / Вера Карпова (devtodev)10 ошибок в работе с аналитикой / Вера Карпова (devtodev)
10 ошибок в работе с аналитикой / Вера Карпова (devtodev)
 
Clad exam preparation_guide_using_lab_view_nxg
Clad exam preparation_guide_using_lab_view_nxgClad exam preparation_guide_using_lab_view_nxg
Clad exam preparation_guide_using_lab_view_nxg
 
Westrich spock-assets-gum
Westrich spock-assets-gumWestrich spock-assets-gum
Westrich spock-assets-gum
 
Behaviour Driven Development with SpecFlow
Behaviour Driven Development with SpecFlowBehaviour Driven Development with SpecFlow
Behaviour Driven Development with SpecFlow
 
Automating sap testing with qtp10 & qc10
Automating sap testing with qtp10 & qc10Automating sap testing with qtp10 & qc10
Automating sap testing with qtp10 & qc10
 
Optimizely NYC Developer Meetup - Experimentation at Blue Apron
Optimizely NYC Developer Meetup - Experimentation at Blue ApronOptimizely NYC Developer Meetup - Experimentation at Blue Apron
Optimizely NYC Developer Meetup - Experimentation at Blue Apron
 
Meetup TestingUy 2017: Automating the Viewer: a cross-functional team approach
Meetup TestingUy 2017: Automating the Viewer: a cross-functional team approachMeetup TestingUy 2017: Automating the Viewer: a cross-functional team approach
Meetup TestingUy 2017: Automating the Viewer: a cross-functional team approach
 
Meetup TestingUy 2017 - Automating the Viewer: a cross-functional team approach
Meetup TestingUy 2017 - Automating the Viewer: a cross-functional team approachMeetup TestingUy 2017 - Automating the Viewer: a cross-functional team approach
Meetup TestingUy 2017 - Automating the Viewer: a cross-functional team approach
 
Fossil Benchmarking Analysis
Fossil Benchmarking AnalysisFossil Benchmarking Analysis
Fossil Benchmarking Analysis
 
Six sigma on burning brownie
Six sigma on burning brownieSix sigma on burning brownie
Six sigma on burning brownie
 
Quick Test Professional (QTP/UFT)
Quick Test Professional (QTP/UFT)Quick Test Professional (QTP/UFT)
Quick Test Professional (QTP/UFT)
 
how to implement agile | 12 principles of agile
how to implement agile | 12 principles of agilehow to implement agile | 12 principles of agile
how to implement agile | 12 principles of agile
 
CV_AUTOMATION_TEST_ENGINEER
CV_AUTOMATION_TEST_ENGINEERCV_AUTOMATION_TEST_ENGINEER
CV_AUTOMATION_TEST_ENGINEER
 

Recently uploaded

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Recently uploaded (20)

tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 

ABAPCodeRetreat 23.7.2016 - Unit Testing

  • 1. © Kaufland 2016 | ABAP CODERETREAT WEINSBERG Unit Testing KIS, Weinsberg, 23.07.2016 ABAP CodeRetreat Weinsberg121.07.2016
  • 2. © Kaufland 2016 | WHO WE ARE KAUFLAND We are more than just a successful international trading company: We are a company where many colleagues become a team, jobs are safe workplaces and real satisfaction Diversity and stability We offer a wide range of jobs with many different entry-levels and career opportunities. Our company is continuously growing, that makes us self-confident Openness and friendly cooperation We support a cooperation based on friendliness and mutual trust ABAP CodeRetreat Weinsberg221.07.2016
  • 3. © Kaufland 2016 | WHERE WE ARE KAUFLAND Expansive growth, economic size • We are successfully expanding in Germany, Poland, Czech Republic, Slovakia, Croatia, Romania and Bulgaria • Over 150,500 employees form our strong Kaufland team in Europe International cooperation and prospects • We offer an international work environment • We provide a wide variety of tasks in collaboration with our international colleagues • According to the area of deployment you will have the opportunity to collect experience abroad, in one of our European locations ABAP CodeRetreat Weinsberg321.07.2016
  • 4. © Kaufland 2016 | ABAP CodeRetreat Weinsberg4 KAUFLAND INFORMATION SYSTEMS We are the IT service provider for Kaufland. Ensuring high business performance and carrying data streams on the right track is our daily responsibility Keep IT simple and safe Our objectives are to comprehensively advice our business departments in designing their business processes and to implement software solutions OUR IT IN FIGURES 21.07.2016 220 SAP Systems 40 SAP Developers 25k Z Reports
  • 5. © Kaufland 2016 | UNIT TESTING ABAP CodeRetreat Weinsberg521.07.2016 Unit Testing Integration Testing System Testing Acceptance Testing
  • 6. © Kaufland 2016 | ABAP CodeRetreat Weinsberg6 • Set up an initial state • Confront the method under test with test values • Compare actual value with expected test value • Implemented in form of test methods • Test methods are hosted in a test class • Test classes are local classes to the program object under test • Use global test classes only to host reusable logic for tests • Comparisons are done with class CL_ABAP_UNIT_ASSERT UNIT TESTS ABAP UNIT TESTS CREATING ABAP UNIT TESTS UNIT TESTING 21.07.2016
  • 7. © Kaufland 2016 | • Test classes are local classes defined with the FOR TESTING addition • Test methods are (private) parameterless instance methods, also declared with the FOR TESTING addition • Use Fixtures to ensure particular starting conditions • [class] setup and [class] teardown TEST CLASSES AND TEST METHODS ABAP CodeRetreat Weinsberg7 UNIT TESTING 21.07.2016 setup( ). teardown( ). my_first_test_method( ).
  • 8. © Kaufland 2016 | EXAMPLE ABAP CodeRetreat Weinsberg8 UNIT TESTING 21.07.2016
  • 9. © Kaufland 2016 | • Testing starts already during the design of your application • The following slides show some pitfalls you should keep in mind • All coding samples are more or less pseudo-code in ABAP style PREPARATION ABAP CodeRetreat Weinsberg9 UNIT TESTING 21.07.2016
  • 10. © Kaufland 2016 | ABAP CodeRetreat Weinsberg10 PITFALL #1 CLASS car. PRIVATE SECTION. DATA g_fuel TYPE i. PUBLIC SECTION. set_fuel IMPORTING i_fuel TYPE i. has_fuel RETURNING r_has_fuel TYPE xfeld. ENDCLASS. CLASS testcar FOR TESTING. PRIVATE SECTION. DATA g_testobject TYPE REF TO car. METHOD class_setup. g_testobject = NEW #( ). METHOD test_fuel. g_testobject->set_fuel( 30 ). METHOD test_has_fuel. DATA(has_fuel) = g_test_object->has_fuel( ). ENDCLASS. UNIT TESTING 21.07.2016 • Test cases guarantee no order! • When method test_has_fuel() is called we do not know in which state the test- object already is! • Take care to initialize your test-object before each testcase so that you know the current state! (e.g. use setup() instead of class_setup()) Each testmethod has to return the same result each time it's called otherwise we cannot test it.
  • 11. © Kaufland 2016 | ABAP CodeRetreat Weinsberg11 PITFALL #2 CLASS order. DATA g_order_number TYPE i. METHOD get_positions. " load data SELECT * FROM mseg WHERE mblnr = g_order_number. " prepare data " do something else " return result. ENDCLASS. UNIT TESTING 21.07.2016 • We do not know what is currently in the database! • We do not know which data will be prepared! • We cannot assume what data will be returned! Do not load information from sources that cannot be controlled during testing. Load data before instantiating the order object. This will enable us to write a testmethod for the data preparation. Alternative solution: use a database- handler-class and pass it as a parameter. During testing you can use a mock of the database-handler that returns fix results.
  • 12. © Kaufland 2016 | ABAP CodeRetreat Weinsberg12 PITFALL #3 CLASS store. METHOD is_opened. CALL FUNCTION 'DATE_COMPUTE_DAY' EXPORTING date = sy-datum IMPORTING day = day. IF day <> 7. r_is_opened = abap_true. ENDIF. ENDCLASS. UNIT TESTING 21.07.2016 • If we expect the store to be closed the testmethod will only succeed on sundays • Testmethods expect a hard-coded result. Not possible in this case! Don't use system (or other) variables that you cannot control. Better give the date as parameter. So your testmethod can call testobject->is_opened( '20160505' ).
  • 13. © Kaufland 2016 | ABAP CodeRetreat Weinsberg13 UNIT TESTING 21.07.2016 POSSIBLE ARCHITECTURE Database Database provider Business object Data Access Object (DAO) Database layer Business layerAccess layer
  • 14. © Kaufland 2016 | • Sample Reports in package: SABP_UNIT_SAMPLE • Executing Tests: Ctrl + Shift + F10 • Verification of test expectations: CL_ABAP_UNIT_ASSERT • Test classes and methods are defined / declared with the FOR TESTING addition • Considerations on how to write testable code must be included in the design avoid the pitfalls HOW TO GET STARTED / KEY TAKEAWAYS ABAP CodeRetreat Weinsberg14 UNIT TESTING 21.07.2016