abap unit and tdd
DESCRIPTION
Introduction into Test Driven Development (TDD) with ABAP Unit. Presented at SAP Inside Track Hamburg (sitHH) 2013: http://wiki.sdn.sap.com/wiki/display/events/SAP+Inside+Track+Hamburg+2013TRANSCRIPT
ABAP Unit and TDD
Hendrik Neumann
SAP Inside Track Hamburg 2013
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
Agenda
Unit Testing & ABAP Unit
Test Driven Development (TDD)
Live Coding
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
Unit Testing
Unit Testing is a method by which
individual units of source code are tested
to determine if they are fit to use.
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
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.
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
xUnit Framework
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
setup( ) test_method( ) teardown( )
assert_*( ) – methods
xUnit Framework
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
setup( ) test_method( ) teardown( )
test_method( )
test_method( )
test_method( )
test_method( )
test_method( )
test_method( )
ABAP Unit
SAP‘s xUnit implemenation
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
ABAP Unit
Local test classes for global dev. artifacts
In Reports, Function Modules and Classes
Not acitve on production systems
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
ABAP Unit
Tools integration:
ABAP Workbench
Code Inspector Integration
ABAP Unit Browser
ABAP Test Cockpit (ATC)
ABAP in Eclipse
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
Test Driven Development
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
Test Driven Development
Never
After you wrote your code
Before you write your code
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
When do you write your Unit Tests?
Test Driven Development
Test Driven Development
Test 1st
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
Test Driven Development
Test Cycle:
red green refactor
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
TDD Cycle
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
Write a test that expresses how you’ll
use the code and what you need it to do.
TDD Cycle
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
Write enough code to get the
test to pass, but no more.
TDD Cycle
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
Clean up the code to remove
redundancy and improve the design.
TDD Cycle
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
Code Kata: Roman Numerals
Copyright © 2013 evivax IT Consulting GmbH
Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]
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.
So Long, and Thanks for All the Fish
Any Qs?
Copyright © 2013 evivax IT Consulting
GmbH Goebelstraße 21 | 64293 Darmstadt | Fon: 06151 - 506420 | e-mail: [email protected]