TestSurgeon is a profiler that monitors the execution of unit tests to collect data on what code is being tested and how. It provides a test similarity metric and visualization to help restructure unit tests. It works by picking a "red" test method, ranking similar "blue" tests, and visualizing their execution differences. This helps define fixture initialization between similar tests and discard superfluous tests. TestSurgeon aims to reduce test size and improve maintenance by spotting differences between tests.
ICT role in 21st century education and its challenges
Restructuring Unit Tests with TestSurgeon - ICSE 2012
1. Restructuring Unit Tests with
TestSurgeon
Pablo Estefó
paestefo@dcc.uchile.cl
Undergrad Student
University of Chile
Programming Languages and Environments for
Intelligent, Adaptable and Distributed systems
2. Why restructuring unit tests?
Unit tests are added when new features are
added
Large amount of unit tests
– Long test execution
– Maintenance issues
– A trivial bug may invalidate many tests
3. My approach: TestSurgeon
TestSurgeon is a profiler for unit tests
Monitors execution of unit tests
Collect data on what is being tested and how
Provides
– Test Similarity metric
– Visualization
4. How does it work?
1) Pick a test method from a large unit tests
(red test)
2) TestSurgeon ranks similar tests (blue test)
3) Visualize the tests execution and their
differences
5. Test Execution Blueprint
methods
Called by Red and Blue test
Called by Blue test
Called by Red test
a base
class
6. Scenario #1: Defining Fixture Initialization
Two test methods in the same unit test
Each test define its own test scenario and they are
similar
8. Example: Scenario #1
MOFormsBuilderTest>>testElementAt (Red test)
MOFormsBuilderTest>>testDisplaying (Blue test)
Solution:
Move what calls the yellow portion in a
setUp method => test size reduction
9. Scenario #2: Discarding superfluous test
method
Small portions of blue or red but not both
Yellow, large and squared shaped methods
11. Example: Scenario #2
MOLayoutTest>>testHorizontalLineLayout (Red test)
MOViewRendererTest>>testCenter (Blue test)
Solution:
Do not consider the blue test for frequent testing
12. Test Surgeon
Profiler for unit tests
Useful to spot differences
Help to restructure tests
Future Work: More accurate
comparison of execution
Comparing groups of tests
State of object receivers
Message arguments
Side effect
Line coverage