Changes for page Test Speedup
Last modified by chrisby on 2025/03/08 11:39
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,7 +1,8 @@ 1 1 Fast testing not only saves time, but also enables more frequent execution, leading to improved code quality. Optimizing the speed of test execution is therefore critical. While extensive and frequent testing is ideal, it shouldn't excessively slow the pace of development. 2 2 3 -### GeneralMeasures3 +### Measures 4 4 5 +* **Test type segregation**: Unit tests tend to run much faster than other types of tests. For large test suites, you should consider running unit tests regularly on the developer's local machine, while scheduling more resource-intensive tests in a CI environment. The CI environment can, for example, run the slower tests in parallel and notify you just in case something fails. If the tests take too long for this approach, you can run them at a fixed rate, usually once a day at midnight. Also see [[Types of Tests|doc:Software Engineering.Testing.Types of Tests.WebHome]]. 5 5 * **Selective Testing**: You don't need to run all tests every time. It can be sufficient to run only the tests related to recently changed code, or only the fast tests, and then run all the tests when you finished a major implementation step. 6 6 * **Mock slow dependencies** to minimize code execution time, especially operations such as I/O, transaction management, and networking. 7 7 * **Prefer in-memory databases during testing** for cleaner and faster operations compared to standard databases. ... ... @@ -9,16 +9,18 @@ 9 9 * If execution time remains constant, CPU is the bottleneck. Mitigate with faster CPUs, more cores, or additional machines. 10 10 * If execution time decreases, I/O is the bottleneck. Use more threads, faster storage (such as SSDs), or additional storage for concurrent filesystem operations. 11 11 * **Improve I/O speed by using RAM disks**, such as Linux's tmpfs tool. Configure your tests to direct all file interactions to the RAM disk. 12 -* **Parallelize test execution.** Multiple threads can improve execution speed even on single-core processors by keeping the CPU busy while other threads wait for disk 13 +* **Parallelize test execution.** Multiple threads can improve execution speed even on single-core processors by keeping the CPU busy while other threads wait for disk I/O. 14 +* **Offload CPU-intensive tasks** to cloud-based computing resources using automation scripts: 15 + * Upload project files to the cloud. 16 + * The cloud service builds the project, runs tests, and generates a test report. 17 + * Upon completion, download the test report from the cloud. 13 13 14 -### Use DevOps Infrastructure19 +### Asynchronous Testing 15 15 16 - A good developer should learn modernDevOps concepts,especially CI/CD pipelines and jobs. Beginners may wantto start with a third-party DevOps infrastructure provider, such as GitLab or GitHub.21 +**Synchronous Testing** 17 17 18 -* **Test type segregation**: Regularly run fast tests, such as unit tests, on the developer's local machine, while scheduling more resource-intensive tests in a CI environment. 19 -* **Asynchronous Testing**: Running the entire test suite locally results in long wait times that block development. Instead, push the code to the source repository and let the CI environment run the test suite while you continue development. If a CI job fails, you will be notified so that you can prioritize fixing the problem. 20 - * **CI Concurrency**: Drastically enhance test execution speed by enabling concurrent CI pipelines and jobs. 21 - * **Concurrent CI pipelines**: Allow the developer to push code and spawn new CI pipelines immediately on different machines, even if previous pipelines are still running. 22 - * **Concurrent CI jobs**: Split the test suite into multiple independently executable CI jobs to allow concurrent execution. 23 - * Both of these measures require multiple machines to run the jobs, which can be demanding on the DevOps infrastructure but is often worth the cost. 24 - * **Scheduled Testing**: A less resource-intensive alternative is to run large test suites at a fixed interval, typically once a day at midnight, and run only the fast or important tests locally. 23 +A simple TDD workflow is to write new code, run tests locally, wait for them to finish, and if they pass, move on. To avoid long wait times, you run only a few very fast tests. This is tolerable when you are working on isolated code and using unit tests, but as soon as integration of the new code with the old code comes into play, it becomes a problem. You have two bad choices: either you run only a few fast tests and do not use the full power of your test suite, possibly missing bugs that would be easier to fix if they were caught earlier, or you run all the tests locally and are unproductive for a long time while waiting for them to finish. This problem can be solved with asynchronous testing. 24 + 25 +**Asynchronous Testing** 26 + 27 +You should have DevOps infrastructure which when pushing code to the code repository triggers a CI pipeline executing all tests. Doing that enables you to directly go on working without the need to wait minutes for the tests to finish. If the CI pipeline succeeds, the comprehensive test suite proofed your code to be fine. If the CI pipeline fails, you should get a notification like an SMS or Email, abort your current work immediately to fix the CI pipeline immediately. This enables quite comprehensive testing, even having the same testing jobs running in parallel, even long taking ones.