Software can easily become complex and difficult to handle - join this session to learn techniques on how to manage and prevent this. You will see how test seams for ABAP simplify unit tests, even in legacy ABAP code with many dependencies. We will demonstrate an OpenSource tool to automatically generate dependency graphs and use it in projects, and the main technique for working with legacy code - writing a characterization test and using it as safety net while making changes.
This presentation was given at the SAP TechED Barcelona 2017
7. Fail fast ->
Reduce costs to handle errors
• Error messages
• ASSERT statements
• Logging
Can be a Smell if it is missed
8. Write down customer
requirements
• Use a requirement engineering tool
• Use a simple Excel sheet with unique ID´s for each
requirement
Can be a Smell if it is missed
9. Do not focus only on
performance
• Field-Symbols are fast, but make coding also harder to
maintain
25. Example for an integration test with unit tests
Open Source project SAP2Moose
• Class z2mse_extract3
• The unit test makes direct accesses to a test application.
• It is an integration test
26. Errors in Unit Tests are easier
to fix than errors in Integration
Tests
• Because the place is known and the complexity is less
43. Use local class for testing with static public attributes
Can be used in Unit test and in the injected code
Can not be used in the productive code (as FOR TESTING)
How to inject variable values?
44. Define a local class for testing
with static public attribute
Empty Seam at place to be checked
Set attribute in injection
Check for value
How to check whether a code snippet is executed?
45. In earlier releases I often failed to
write Unit Test for typical ABAP
code.
It was too complex and risky
46. With ABAP 7.50
I am normally successful
Test Seams make writing Unit Test easier
47. I use Test Seams when they help
for old and for new coding
48. This tests are also on Github
https://github.com/RainerWinkler/ABAP-Unit-Test-Demo
Synchronized with abapGit (Why not? „Install abapGit make a fork and make a pull request to this“):
49.
50. Typical workflow while changing
Legacy Code
1 Add Unit test to
- understand
- have a safety belt
2 Refactor to simplify changes
3 Change Unit test so that it passes
only after changes are made
4 Make changes in the code
51.
52. There is a lot of text in Coding
I have problems to remember this
Why are there so few
"circuit diagrams" in IT?
54. I draw diagrams but it needs a lot of time
Can this be automatized?
SAP Inside Track
Munich 20151
1 https://wiki.scn.sap.com/wiki/display/events/SAP+Inside+Track+Munich+2015
56. While exploring many new files,
developers gradually forget
which ones are relevant or irrelevant to their goal
and how these files are related to each other.
Lee, Seonah, and Sungwon Kang. "What situational information would help developers when using a graphical code recommender?." Journal of Systems and Software 117 (2016): 199-217.
De Alwis, Brian, and Gail C. Murphy. "Using visual momentum to explain disorientation in the Eclipse IDE." Visual Languages and Human-Centric Computing, 2006. VL/HCC 2006. IEEE Symposium on. IEEE, 2006.
57. While switching between these files to
understand them,
developers become disoriented.
Lee, Seonah, and Sungwon Kang. "What situational information would help developers when using a graphical code recommender?." Journal of Systems and Software 117 (2016): 199-217.
De Alwis, Brian, and Gail C. Murphy. "Using visual momentum to explain disorientation in the Eclipse IDE." Visual Languages and Human-Centric Computing, 2006. VL/HCC 2006. IEEE Symposium on. IEEE, 2006.
58. While performing multiple tasks simultaneously,
developers fail to focus on one task
due to the others,
and unconsciously move on to
other tasks
without accomplishing the initial task.
Lee, Seonah, and Sungwon Kang. "What situational information would help developers when using a graphical code recommender?." Journal of Systems and Software 117 (2016): 199-217.
De Alwis, Brian, and Gail C. Murphy. "Using visual momentum to explain disorientation in the Eclipse IDE." Visual Languages and Human-Centric Computing, 2006. VL/HCC 2006. IEEE Symposium on. IEEE, 2006.
66. • Extracts meta information to Moose
• Does not extract source code
• Easy to install (A single report)
• Developed using abapGit
• Works on ABAP 7.02
• MIT license
SAP2Moose
67. • An open source Software Exploration Tool
• Designed to be used by developers working with legacy code
• Displays not only ABAP classes but also tables, WebDynpro ABAP, SAP BW...
• Jump into ABAP Eclipse with ADT and BWMT links possible
• Can be adapted
• Diagrams can be customized, elements can be commented
• Changes can be stored
• MIT license
Moose2Model
68. SAP2Moose - Installation
Go to SAP2Moose.org
You are forwarded to github,
Extracted are only names and relations between elements, no source code
Read Wiki - Installation
Go to Code and click on z_moose_extractor.abap
and z_moose_extractor_texts.txt
Paste code into new program, add texts from file,
run it
69. Moose2Model - Installation
Go to Moose2Model.org
You are forwarded to github,
read Wiki - Installation
Download the preconfigured image
Extract zip file and start Pharo.exe
The image is ready to work
No need to start a program
Smalltalk programs behave like an
Excel file, you save them, but you
do not start them (normally)
70. Simple Gui
Pharo leaves always some space, because desktop is needed
Display the most important at the top, it will normally be visible there
The green "thing"
72. Moose2Model - Stopping
Make a left mouse click to the desktop
You see the World menu
Choose Save and quit
Or just Quit without saving if the exact status
of the Image is not needed to be saved
73. Demo 2
• Install SAP2Moose
• Run SAP2Moose
• Install Moose2Model
• Use Moose2Model
• Stop Moose2Model
74. How to make a diagram?
I do normally:
1. Navigate to an attribute or method and send
RWDiagram suppressOthersUsedByLayers: 1 usingLayers: 1 to: self.
2. Generate a diagram with formatting info
3. Send RWDiagram suppressOthersUsedByLayers: 1 usingLayers: 1 to: self.
to further elements as required
4. Redo the suppress... statement with
RWDiagram removeAppearanceChangersFrom: self.
if needed
5. Suppress some classes (like logging) with
RWDiagram suppressWithChildren: true to: self.
75.
76. I need no Diagrams - What else can I do with it?
SAP2Moose - Multilevel Where Used
Compare with the diagram
77. I see too
many elements
Restrict diagram to packages
Thanks to Stefan Nothaft for believing in and requiring the option to restrict diagrams to packages and classes
or classes
78. I want a fast way to
navigate to the coding
SAP2Moose provides ADT1 and BWMT2 Links
1Currently not for interface methods and some other elements
2Currently only to some SAP BW transformations
Two clicks;
and method is shown in Eclipse ADT
works also for the class
79. There are very many elements
with nearto similar names
I am confused
Use the picture
80. A method that implements an
interface appears not used
SAP2Moose marks implementing method as
used by interface method - which is used
Sorry for the method names. The example is part of the integration test of SAP2Moose, the names are long to check that no information is lost due to too long names
81. A method appears not used
SAP2Moose marks redefining method as
used by redefined method - which is used
83. The idea is to have as much information as possible on a page
• Straight lines leed to hair-nots,
• but they make very clear where they are pointing to
• rearranging is very easy in the tool1
1A coding to rearange elements automatically exists, but is currently not used by the author, because manual rearranging appears to be more convenient
Moose2Model is not designed for nice presentations
84. I need to exchange diagrams
with colleagues
Diagram information is exported as xml
Can be synchronized with a version control system
See e.g. subfolder models
of SAP2Moose and
Moose2Model
85. I use other computer languages
or something that is
not even called programming
• Like SAP BW
Moose Analysis is designed for many languages
SAP2Moose maps:
• "coding" to methods
• "data bearing entities" to attributes
• "groupings" to classes
• "higher level groupings" to packages
86. Elements are dynamically called
I do not see this in Where Used
Add a comment in
Moose2Model1:
1This only a demo. The method Z2MSE_MSE_HARMONIZE>>MSE_2_HARMONIZED is used in unit tests, these are currently not extracted by SAP2Moose
It is planned to support custom logic
to add such dependencies to the extracted model
87. All what is done with SAP2Moose
and Moose2Model can also be done without
- So why do I need it?
The problem is not do perform a single task
- Complex coding, Legacy coding - requires that many tasks are done
with limited time and budget
I used to make about a dozen diagrams per year
With SAP2Moose and Moose2Model
I make thousands
88. The diagram is not as expected
This happens quite often
Often caused by "trivial" bugs
Difficult to see in the coding but
easy to see in a diagram
This reduces the cost to find
and fix errors
89. I am confused by wrong names
Add a comment
to explain what the real meaning is
1Names could be renamed in SAP2Moose or Moose2Model if needed
"Virtual" renaming is an option1
90. Why not plantUML?
plantUML is great for UML
But analyzing existing code needs more details
Moose uses FAMIX and is able to extract more detailed informations
It is possible to design a new software based on classes
But it is NOT possible to understand problematic software
by analyzing classes
plantUML is a tool to draw diagrams,
Moose2Model and SAP2Moose are Software Exploration Tools
91. Why no display of inheritances?
Why no info on attributes like
static, public, private?
Such informations can be stored and
analyzed in Moose Analysis
But to analyze dependencies of
existing code, I do not regard this needed
92. How to understand which
dependencies
are shown?
Generate a diagram with formatting info
Z2MSE_EXTR3_ELEMENTS>>MAKE_MODEL
is not highlighted because it contains
the information to display all
connected elements
Only a workaround that works if allways
using and used by layers is set to greater zero
93. Where to send statements to Moose elements?
In the Moose Panel
Context menu "Do it" Ctrl-D
94. Where to send statements to Moose elements?
In the inspector of a diagram
Click on the element
Context menu "Do it" Ctrl-D
95. Where to send statements to Moose elements?
Wherever you find it.
It exists as instance in the image. You can alway send
statements and questions to it.
96. I draw diagrams
If I make an error,
I will make wrong decisions
SAP2Moose and Moose2Model have
limitations and errors
• These are reproducible and I can learn to circumvent then
• Generally the total number of errors is much less
compared to a developer who analyzes an application
solely manually
97. What are the elements I work with?
Make a diagram with all these
Layout
Moose2Model Issue 39 Simplify handling of diagrams
available also on Github
98. Find obsolete coding
Method is not used in the diagram
Other option: Find potentially obsolete Methods in Moose Panel with:
each incomingInvocations size = 0
99. Thank you!
SAP2Moose and Moose2Model would never
be possible without
Damir Majer
Tudor Girba
Alexandré Bergel
And many others,
I have no place to mention here
100. Have fun
Look for Test Seam on SCN
sap2moose.org
moose2model.org
Twitter: @rainerwinkler
Open an issue on github,
this is the most efficient way to get help
- Not understanding points to bad documentation
-> The easiest way to help is to documentate <-