Contents
Should unit tests run quickly?
Developers should be able to run the whole suite of unit tests in seconds, and definitely not in minutes and minutes. Developers should be able to quickly run them after changing the code in anyway. If it takes too long, they won’t bother running them and you lose one of the main benefits of the tests.
How fast should unit test run?
Still, it seems as though a 10 second short-term attention span is more or less hard-wired into the human brain. Thus, a unit test suite used for TDD should run in less than 10 seconds. If it’s slower, you’ll be less productive because you’ll constantly lose focus.
How to speed up execution of unit tests?
Some frameworks provide automatic execution of specific unit tests based on heuristics such as last-modified time. For Ruby and Rails, AutoTest provides much faster and responsive execution of the tests — when I save a Rails model app/models/foo.rb, the corresponding unit tests in test/unit/foo_test.rb get run.
How long does it take for a unit test to run?
A unit test that runs more than a few seconds is a rarity. Performance tests can take time to set up and run, particularly when the test executes a number of tasks during a testing session—for example, performance testing a large number of pages on a website.
Why do unit tests need to be fast?
The rule of thumb is that unit tests need speed and performance tests need time. Therefore, unless they’re planned properly, one can get in the way of the other and impede the effectiveness and efficiency of the entire testing process in the CI/CD pipeline. As mentioned above, unit tests are intended to be run fast.
When to run shifting left in unit testing?
Short-running performance tests, such as those measuring the time it takes for a single query to run or a series of nested forEach loops to execute, are appropriate for shifting left, provided they can run in under a second. Performance tests that take longer to run need to run later in the test plan.