Test factoring creates fast, focused unit tests from slow system-wide tests; each new unit test exercises only a subset of the functionality exercised by the system test. Augmenting a test suite with factored unit tests should catch errors earlier in a test run. One way to factor a test is to introduce mock objects. If a test exercises a component T, which interacts with another component E (the “environment”), the implementation of E can be replaced by a mock. The mock checks that T’s calls to E are as expected, and it simulates E’s behavior in response. We introduce an automatic technique for test factoring. Given a system test for T and E, and a record of T’s and E’s behavior when the system test is run, test factoring generates unit tests for T in which E is mocked. The factored tests can isolate bugs in T from bugs in E and, if E is slow or expensive, improve test performance or cost. Our implementation of automatic dynamic test factoring for the Java language reduces...
David Saff, Shay Artzi, Jeff H. Perkins, Michael D