Abstract | \emphTest 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. \par One way to factor a test is to introduce \emphmock 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 \em 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. \par Our implementation of automatic dynamic test factoring for the Java language reduces the running time of a system test suite by up to an order of magnitude. |