Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
TDD – Test Driven Development
Hendrik Neumann
Agenda
(1) Unit Testing
(2) ABAP Unit
(3) Test Driven Development
Unit Testing
Unit Testing
Definition
Unit Testing
Unit Testing is a method by which
individual units of source code are
tested to determine if they are fit to
...
Unit Testing
Unit Testing is a method by which
individual units are e.g.ource code
fittMethods of t Function Modules fit
F...
Unit Testing
aim:
Find bugs early
Write once, run often
Effective Tests must be automated
solution:
xUnit Frameworks
xUnit Framework
xUnit Framework
Definition
xUnit Framework
Provides an automated solution with no
need to write the same tests many times
and no need to remember wha...
xUnit Framework
How does it work?
xUnit Framework
setup()
creates object under test
– used in all tests
xUnit Framework
setup()  test_method()
Clear up your
mess..
calls object under test
– e.g. a public method
with test data
xUnit Framework
setup()  test_method()
assert_*()–methods
verify the return value of
the object under test using
xUnit’s ...
xUnit Framework
setup()  test_method() teardown()
Clear up your
mess..
xUnit Framework
setup()  test_method() teardown()
test_method()
test_method()
test_method()
test_method()
test_method()
...
ABAP Unit
ABAP Unit
SAP‘s xUnit implemenation
ABAP Unit
cl_abap_unit_assert=>assert_equals(
msg = 'Test msg'
act = act
exp = out->( )
).
assert_*()-Methods
ABAP Unit in ADT
ABAP Unit
Local test classes for global
development artifacts
In Reports, Function Modules and
Classes
Not acitve on produ...
ABAP Unit
• Tools integration:
–ABAP Workbench
–Code Inspector Integration
–ABAP Unit Browser
–ABAP Test Cockpit (ATC)
–AB...
Test Driven Development
Test Driven Development
• Never
• After you wrote your code
• Before you write your code
When do you write your Unit Tests?
Test Driven Development
• Never
• After you wrote your code
• Before you write your code
When do you write your Unit Tests...
Test Driven Development
Test 1st
Test Cycle
Test
Write a test that expresses how you’ll use
the code and what you need it to do.
Test Cycle
Write enough code to get
the test to pass, but no
more.
Code
Test
Test Cycle
Code
Test
Refactor
Clean up the code to
remove redundancy and
improve the design.
Test Cycle
Code
Test
Refactor
Test Cycle
Code
Test
Refactor
Test Cycle
Code
Test
Refactor
Test Cycle
Code
Test
Refactor
Green Bar Patterns
Green Bar Patterns
Fake it till you make it
• Start with hardcoded results and wait
until tests force them to become real
Green Bar Patterns
Triangulate To Abstraction
• Make the code abstract only when you
have two or more examples
Green Bar Patterns
Obvious Implementation
• aka Don‘t be stupid
• If you really know the right way to
implement it, do it ...
Have FUN!
Backup
Code Kata: Roman Numerals
Rules:
• smaller number in front of a larger number  subtraction
• all else  addition
• put on...
Upcoming SlideShare
Loading in …5
×

ABAP Code Retreat Frankfurt 2016: TDD - Test Driven Development

1,197 views

Published on

ABAP Code Retreat Frankfurt 2016

Introduction into Test Driven Development itself and how it is done with ABAP and ABAPUnit

Published in: Technology
  • Login to see the comments

ABAP Code Retreat Frankfurt 2016: TDD - Test Driven Development

  1. 1. TDD – Test Driven Development Hendrik Neumann
  2. 2. Agenda (1) Unit Testing (2) ABAP Unit (3) Test Driven Development
  3. 3. Unit Testing
  4. 4. Unit Testing Definition
  5. 5. Unit Testing Unit Testing is a method by which individual units of source code are tested to determine if they are fit to use.
  6. 6. Unit Testing Unit Testing is a method by which individual units are e.g.ource code fittMethods of t Function Modules fit Function Groups fiMoModule Pools Function Functn Reports Methods Function Groups
  7. 7. Unit Testing aim: Find bugs early Write once, run often Effective Tests must be automated solution: xUnit Frameworks
  8. 8. xUnit Framework
  9. 9. xUnit Framework Definition
  10. 10. xUnit Framework Provides an automated solution with no need to write the same tests many times and no need to remember what should be the result of each test.
  11. 11. xUnit Framework How does it work?
  12. 12. xUnit Framework setup() creates object under test – used in all tests
  13. 13. xUnit Framework setup()  test_method() Clear up your mess.. calls object under test – e.g. a public method with test data
  14. 14. xUnit Framework setup()  test_method() assert_*()–methods verify the return value of the object under test using xUnit’s assert methods
  15. 15. xUnit Framework setup()  test_method() teardown() Clear up your mess..
  16. 16. xUnit Framework setup()  test_method() teardown() test_method() test_method() test_method() test_method() test_method() test_method()
  17. 17. ABAP Unit
  18. 18. ABAP Unit SAP‘s xUnit implemenation
  19. 19. ABAP Unit cl_abap_unit_assert=>assert_equals( msg = 'Test msg' act = act exp = out->( ) ).
  20. 20. assert_*()-Methods
  21. 21. ABAP Unit in ADT
  22. 22. ABAP Unit Local test classes for global development artifacts In Reports, Function Modules and Classes Not acitve on production systems
  23. 23. ABAP Unit • Tools integration: –ABAP Workbench –Code Inspector Integration –ABAP Unit Browser –ABAP Test Cockpit (ATC) –ABAP in Eclipse
  24. 24. Test Driven Development
  25. 25. Test Driven Development • Never • After you wrote your code • Before you write your code When do you write your Unit Tests?
  26. 26. Test Driven Development • Never • After you wrote your code • Before you write your code When do you write your Unit Tests? Test Driven Development
  27. 27. Test Driven Development Test 1st
  28. 28. Test Cycle Test Write a test that expresses how you’ll use the code and what you need it to do.
  29. 29. Test Cycle Write enough code to get the test to pass, but no more. Code Test
  30. 30. Test Cycle Code Test Refactor Clean up the code to remove redundancy and improve the design.
  31. 31. Test Cycle Code Test Refactor
  32. 32. Test Cycle Code Test Refactor
  33. 33. Test Cycle Code Test Refactor
  34. 34. Test Cycle Code Test Refactor
  35. 35. Green Bar Patterns
  36. 36. Green Bar Patterns Fake it till you make it • Start with hardcoded results and wait until tests force them to become real
  37. 37. Green Bar Patterns Triangulate To Abstraction • Make the code abstract only when you have two or more examples
  38. 38. Green Bar Patterns Obvious Implementation • aka Don‘t be stupid • If you really know the right way to implement it, do it that way
  39. 39. Have FUN!
  40. 40. Backup
  41. 41. Code Kata: Roman Numerals Rules: • smaller number in front of a larger number  subtraction • all else  addition • put only one smaller number in front of a larger number • ones, tens, hundreds and thousands are separate items I The numeral one. II is two, III is three. V The numeral 5. IV is 4, VI is 6, VII is 7, VIII is 8. X The numeral 10. IX is 9, XI is 11, etc. L The numeral 50. XL would be 40. C The numeral 100. C is short for the Latin word Centum, but Century is eaysier to remember ;-) D The numeral 500. M The numeral 1000.

×