@gil_zilberfeld@gil_zilberfeld
Zen and the Art of
Test Maintenance
@gil_zilberfeld
Hello!
I AM GIL ZILBERFELD
www.gilzilberfeld.com
www.everydayunittesting.com
@gil_zilberfeld
@gil_zilberfeld
For the exercises:
◉ https://github.com/gilzilberfeld/test-maintenance-exercises
◉https://bit.ly/2JaM3Pb
◉Also a Diff tool (KDiff3)
@gil_zilberfeld@gil_zilberfeld
Test Maintenance
What is it good for?
@gil_zilberfeld
@gil_zilberfeld
The value of our tests
◉ Alignment with product focus
◉ Cover the right areas
◉ Stability
◉ Find bugs
◉ Pinpoint the problems
@gil_zilberfeld@gil_zilberfeld
Strategy
@gil_zilberfeld
@gil_zilberfeld@gil_zilberfeld
Once we got a map
We can create a plan of where we want to go
@gil_zilberfeld
High level view
◉ What is important for the product?
◉ What are the risks?
◉ What should we focus on?
◉ At this stage and the short-mid term future
@gil_zilberfeld
@gil_zilberfeld@gil_zilberfeld
What about Facebook?
Importance, risk, focus
@gil_zilberfeld
◉ Important:
◉ Risks
◉ Focus
Ad sales, trust
Losing money, finding out what we
really do, showing relevant
information
Algorithms
Facebook
@gil_zilberfeld@gil_zilberfeld
What about Kayak?
Importance, risks, focus
@gil_zilberfeld
◉ Important:
◉ Risks:
◉ Focus:
Commerce, Immediacy
Dependency on other systems
Information, reliability, accuracy
Integration
Kayak
@gil_zilberfeld
@gil_zilberfeld
◉ The tests we have
◉ The workflows we
cover (value)
◉ The risks we answer
◉ The costs incurred by
the tests
◉ The dependencies we
rely on
◉ The architecture
◉ The resources
◉ The skills
Testing cartography
@gil_zilberfeld
@gil_zilberfeld
◉ “Main” Workflow
coverage
◉ Architectural stability
◉ Workflow stability
◉ Manual regression
testing time
◉ Time to feedback
◉ Escaped bugs that we
could have found(by
customer or internally)
What to track
@gil_zilberfeld
@gil_zilberfeld
Calculator Requirements
@gil_zilberfeld
Exercise
◉ Build a test plan
◉ Examine the code and tests
◉ Recommend what to do next
◉ And why
@gil_zilberfeld
@gil_zilberfeld
Test suite clean up
◉ Organize sanity, regression and acceptance
◉ Delete “Ignored” tests
◉ Fix grouping for test cohesion
@gil_zilberfeld
When adding tests
◉ Add tests at the right level
◉ Move “older stable” area tests to later build
cycles
◉ Move “newer unstable” area tests to earlier
cycles
@gil_zilberfeld
@gil_zilberfeld
Exercise: Unit Tests
◉ Find issues and ways to improve
◉ Refactor the tests
◉ Save the older version
@gil_zilberfeld
@gil_zilberfeld
Uninformative tests
◉ Tests that don’t point to the problem
◉ Not enough information on failure
◉ Checking too many operations
◉ No overlapping between test types
(triangulation)
@gil_zilberfeld
@gil_zilberfeld
Unreliable tests
◉ Inability to consistently run anywhere, anytime
◉ Flaky tests
◉ Dependency on unstable resources, platforms
◉ Test isolation (resources, initialization, cleanup)
@gil_zilberfeld
@gil_zilberfeld
◉ Data transformation
◉ Tests that always pass
◉ Unclear test names
◉ Logic in tests
◉ Readability
◉ Code matching
◉ No assertions
Misleading tests
@gil_zilberfeld
@gil_zilberfeld
Tests that hurt you
◉ Hard to setup
◉ Test run length
◉ Build cycle run length
@gil_zilberfeld
@gil_zilberfeld
Maintenance issues
◉ Copy-paste, duplication
◉ Where do I add the next test?
◉ Tests that do same thing “just to be on the safe
side”
◉ Verbose and big setup, no framework (Page
object)
@gil_zilberfeld
Exercise: Integration tests
◉ Check out the integration tests
◉ Also consider the unit tests!
◉ Refactor
◉ Save the original version
@gil_zilberfeld
@gil_zilberfeld
Lazy creates the norm
◉ Copy-and-paste duplication
◉ Bigger tests over smaller ones
◉ It may not be that good for you
@gil_zilberfeld
Exercise: Adding tests for existing functionality
◉ From the list of your test plan
◉ Reorganize the suite
◉ Decide where to put it
◉ Find where it hurts and why
@gil_zilberfeld
@gil_zilberfeld
Testability
◉ Accessibility
◉ Seams
◉ Big setup and mocks
◉ Shared state
◉ Unknown side effects
@gil_zilberfeld
@gil_zilberfeld@gil_zilberfeld
Refactoring for testability
And a very short introduction to ApprovalTests
@gil_zilberfeld
Characterization tests
◉ Describe the existing state of the implementation
◉ Run the test without an assert
◉ Capture the result in an assert
◉ Then we can refactor
@gil_zilberfeld
ApprovalTests
◉ Open-source tool for approval testing
◉ Used to lock a state by capturing output
◉ Can be used as a substitute for “other” tests
◉ Creates a Golden Standard
◉ Start refactoring with small steps
@gil_zilberfeld
@gil_zilberfeld
Exercise
◉ Write up a few tests cases in an Approval test
◉ Refactor the code after adding the tests
◉ Replace the approval tests with “regular” tests
@gil_zilberfeld
@gil_zilberfeld
Behavior Driven Development
◉ Created to allow “humans” to read the tests
◉ Gherkin statements are translated into “glue”
code that operate the underlying code
◉ You don’t really need it for that
◉ But it may be beneficial in some cases
@gil_zilberfeld
@gil_zilberfeld
Exercise
◉ Write the multi-parameter test in Gherkin and
add the implementation
◉ How would you rearrange the tests given this
capability
@gil_zilberfeld
@gil_zilberfeld@gil_zilberfeld
Test reviews
Why?
@gil_zilberfeld
Why review?
◉ Find problems early
◉ Fight complexity
◉ Knowledge sharing
◉ Collective code ownership
◉ Maintain conventions
@gil_zilberfeld@gil_zilberfeld
Ask: Can I maintain this code?
@gil_zilberfeld
Who reviews?
◉ Team lead
◉ Architect
◉ Developer
◉ Peers
◉ The person who can bring the most value
@gil_zilberfeld
@gil_zilberfeld
Short reviews
◉ Short reviews means higher availability
◉ No more than 60 minutes
◉ No more than 200 lines of code
◉ Less is better
@gil_zilberfeld
Async review
◉ Smell of attitude
◉ Better together
◉ Better for distributed teams
◉ Consider the commit status
@gil_zilberfeld
@gil_zilberfeld@gil_zilberfeld
Errors will be found!
@gil_zilberfeld
@gil_zilberfeld
When to review?
◉ Before committing
◉ After merging
◉ When you’re ready
@gil_zilberfeld
What to review?
◉ Functionality
◉ Are all necessary cases covered?
◉ Are they written correctly?
◉ Is the test run time quick?
◉ Remove ignored tests
@gil_zilberfeld
What to review?
◉ “What if” scenarios
◉ English
◉ Performance
◉ Impact on other systems
◉ Dependency on other systems
@gil_zilberfeld
What to review?
◉ Compliance
 Conventions
 Tools
 Legal
@gil_zilberfeld
@gil_zilberfeld
Pair programming and testing
◉ Better together
◉ No need to review!
◉ Be nice
@gil_zilberfeld
Exercise: Review the changes
◉ Pair with someone
◉ Express views
◉ Try to stick to the patterns
@gil_zilberfeld
@gil_zilberfeld
Thanks!
ANY QUESTIONS?
You can find me at:
@gil_zilberfeld
http://www.GilZilberfeld.com
http://www.EverydayUnitTesting.com

Zen and the Art of Test Maintenance