Dynamic Unit Test Extraction via Time Travel Debugging for Test Cost Reduction
Compared to system tests, unit tests execute faster and allow more precise fault localisation. Hence, it can be beneficial to automatically extract unit tests and displace associated system tests. However, the extraction process may encounter challenges such as the identification of relevant test objectives, scalability issues, and future maintainability of serialized state. To address these challenges, we exploit time travel debugging for efficient and accurate reconstruction of object states and use differential analysis of code coverage data. This allows us to extract code-only unit tests for a very large industrial C++ project with a feasible overhead. The extracted unit tests mimic relevant parts of the system tests and, by displacing the latter in early testing stages, save resources. Our evaluation on SQLite and a very large industrial C++ project indicates a large potential for test cost reduction with our technique. The extraction process for the industrial project results in an average slowdown factor of 14. All of 789 extracted unit tests have passed code reviews and were accepted by developers of the industrial project.