Testing in Legacy: From Rags to Riches
About me
{
“First name”: “Taras”,
“Last name”: “Slipets”,
“E-mail”: “[email protected]”,
“LinkedIn Profile”: “http://www.linkedin.com/
pub/taras-slipets/
48/466/516”,
“Interests”: [
“Software Engineering”,
“Music”
]
}
2
About presentation
3
I’d like to share our experience
4
What does it mean – Legacy system?
5
Ask expert
6
Legacy system is…
7
Just long-term project
8
What we’ve received
• 11-years old system SUCCESSFULLY running on production servers
• Written in Java 1.4
• No frameworks usage
• No documentation
• No developers who has worked on it
• Impatient customers
• Pantient management
• other surprises…
9
Bus factor
10
What we’d like to have?
11
What we’d like to have?
12
Shiny system with all cutting-edge frameworks
Reduce pain of maintenance and support
What we’d like to have?
13
Shiny system with all cutting-edge frameworks
Reduce pain of maintenance and support
So, how we did it?
14
15
Logs, logs, logs
16
Domain model – classes level
17
Domain model – database level
18
Domain model – workflows
19
Peer review VERY often
20
Before changing code
21
We need to ensure it works
22
Testing
23
Testing levels
• Unit tests
• Integration tests
• System tests
24
Unit tests
25
Integration tests
26
System tests
27
Test existing and expected behavior
28
System testing (feature testing)
29
Application under testing
System tests
Process Process
External world communication
30
External world communication - mocks
31
External world communication - mocks
32
External world communication - mocks
33
External world communication - mocks
34
System tests automation
35
Finally – let’s touch code!
36
Top occurring issues
• “do-stuff” methods
• “I’m aware of everything” classes
• “Celebrities” classes/interfaces
• “Magic goes here” blocks without comments
• Just obsolete code
37
What to do?
38
How about
39
40
Refactoring facilities
• Extract method
• Extract interface
• Parameter object
• Method object
• Replace type-checking code with State/Strategy
• Move method/field
• …
41
Unit tests jumps into
42
Frameworks
• EasyMock
• Mockito
• PowerMock
43
Indication
After initial tests are written, use PowerMock as indicator of bad system design
44
What is next?
45
46
47
Most used in our case
• Template method
• Strategy
• State
• Visitor
• Command
• Chain of Responsibility
• Observer
48
49
And again - logs, logs, logs
50
Hey, where are new features?
51
Extend functionality AFA it’s possible
52
How deep refactoring should be?
53
Theory the Godmother
• S.O.L.I.D.
• D.R.Y.
• K.I.S.S.
• …
54
In real world
55
Now we can add integration tests
56
What about build/deployment time?
57
Simple rule
58
But for us it hurt
59
Remedy?
60
Remedy
61
• Make app self-contained
• Simplify manual installation
Operations are happy
62
If it steal hurts - automate deployment
63
Complete features list + tests for them
64
The winner takes it all
65
The dreams come true - build-pipeline!
66
A-team!
67
Links
• http://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052
• http://xpdays.com.ua/archive/xp-days-ukraine-2011/materials/legacy/
• http://xpdays.com.ua/archive/xp-days-ukraine-2012/materials/code-story/
• http://jeeconf.com/archive/materials-2014/legacy-projects/
• http://jeeconf.com/materials/web-application-i-have-always-dreamt-of/
68
Thanks for your attention!
69