James R Sullivan

Test driven development requires you run your tests a lot. Even with a fast machine testing time adds up. I am currently working on a Python test suite using unittest which takes 7 seconds to run all of them. That time is going to grow as the number of tests increase, so the first step to speeding it up is to isolate the test you run.

    <p>
      When you are working in one file or one section of the app, just run those tests only:
      <pre>
      <code> python -m unittest -q test.UserTest.test_list_users_requires_auth </code>
      </pre>
    </p>
    <p>
      When working on auth, logging, or exception handling code within a framework you may want to run all tests constantly.
      In Python I use <a href="https://github.com/testing-cabal/testtools">testtools</a> with <a href="https://github.com/cgoldberg/concurrencytest">concurrencytest</a> which just extends the normal <code>unittest</code> module and gives you parallel test execution (among other things).
      <pre>
      <code> if __name__ == "__main__":
from concurrencytest import ConcurrentTestSuite, fork_for_tests
suite = unittest.TestSuite(tests=(
    unittest.TestLoader().loadTestsFromTestCase(TestUser),
    unittest.TestLoader().loadTestsFromTestCase(TestSupportCase),
    unittest.TestLoader().loadTestsFromTestCase(TestError),
    unittest.TestLoader().loadTestsFromTestCase(TestPing)
))
concurrent_suite = ConcurrentTestSuite(suite, fork_for_tests(4))
unittest.TextTestRunner().run(concurrent_suite) </code>
      </pre>
      The which made me what to share this runs now in 3 or less seconds compared to the 7.5 seconds before.
    </p>